diff options
Diffstat (limited to 'railties/test')
22 files changed, 333 insertions, 29 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index 9c866263f0..9600194ed6 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -32,3 +32,5 @@ class ActiveSupport::TestCase skip message if defined?(JRUBY_VERSION) end end + +require_relative "../../tools/test_common" diff --git a/railties/test/application/asset_debugging_test.rb b/railties/test/application/asset_debugging_test.rb index 3e0f31860b..7623e8e352 100644 --- a/railties/test/application/asset_debugging_test.rb +++ b/railties/test/application/asset_debugging_test.rb @@ -95,7 +95,7 @@ module ApplicationTests end end - test "public url methods are not over-written by the asset pipeline" do + test "public URL methods are not over-written by the asset pipeline" do contents = "doesnotexist" cases = { asset_url: %r{http://example.org/#{contents}}, diff --git a/railties/test/application/assets_test.rb b/railties/test/application/assets_test.rb index 46ee0d670e..a80581211b 100644 --- a/railties/test/application/assets_test.rb +++ b/railties/test/application/assets_test.rb @@ -450,7 +450,7 @@ module ApplicationTests assert_equal 0, files.length, "Expected application.js asset to be removed, but still exists" end - test "asset urls should use the request's protocol by default" do + test "asset URLs should use the request's protocol by default" do app_with_assets_in_view add_to_config "config.asset_host = 'example.com'" add_to_env_config "development", "config.assets.digest = false" @@ -466,7 +466,7 @@ module ApplicationTests assert_match('src="https://example.com/assets/application.self.js', last_response.body) end - test "asset urls should be protocol-relative if no request is in scope" do + test "asset URLs should be protocol-relative if no request is in scope" do app_file "app/assets/images/rails.png", "notreallyapng" app_file "app/assets/javascripts/image_loader.js.erb", "var src='<%= image_path('rails.png') %>';" add_to_config "config.assets.precompile = %w{rails.png image_loader.js}" diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index e34c075a1c..b8e167b488 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -2476,6 +2476,22 @@ module ApplicationTests assert_includes Rails.application.config.hosts, ".localhost" end + test "disable_sandbox is false by default" do + app "development" + + assert_equal false, Rails.configuration.disable_sandbox + end + + test "disable_sandbox can be overridden" do + add_to_config <<-RUBY + config.disable_sandbox = true + RUBY + + app "development" + + assert Rails.configuration.disable_sandbox + end + private def force_lazy_load_hooks yield # Tasty clarifying sugar, homie! We only need to reference a constant to load it. diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb index b6270525f0..db16f4cc56 100644 --- a/railties/test/application/console_test.rb +++ b/railties/test/application/console_test.rb @@ -123,13 +123,17 @@ class FullStackConsoleTest < ActiveSupport::TestCase assert_output "> ", @primary end - def spawn_console(options) - Process.spawn( + def spawn_console(options, wait_for_prompt: true) + pid = Process.spawn( "#{app_path}/bin/rails console #{options}", in: @replica, out: @replica, err: @replica ) - assert_output "> ", @primary, 30 + if wait_for_prompt + assert_output "> ", @primary, 30 + end + + pid end def test_sandbox @@ -148,6 +152,17 @@ class FullStackConsoleTest < ActiveSupport::TestCase @primary.puts "quit" end + def test_sandbox_when_sandbox_is_disabled + add_to_config <<-RUBY + config.disable_sandbox = true + RUBY + + output = `#{app_path}/bin/rails console --sandbox` + + assert_includes output, "sandbox mode is disabled" + assert_equal 1, $?.exitstatus + end + def test_environment_option_and_irb_option spawn_console("-e test -- --verbose") diff --git a/railties/test/application/initializers/frameworks_test.rb b/railties/test/application/initializers/frameworks_test.rb index 3cd4b8fe33..a35247fc43 100644 --- a/railties/test/application/initializers/frameworks_test.rb +++ b/railties/test/application/initializers/frameworks_test.rb @@ -39,7 +39,7 @@ module ApplicationTests assert_equal expanded_path, ActionMailer::Base.view_paths[0].to_s end - test "allows me to configure default url options for ActionMailer" do + test "allows me to configure default URL options for ActionMailer" do app_file "config/environments/development.rb", <<-RUBY Rails.application.configure do config.action_mailer.default_url_options = { :host => "test.rails" } @@ -61,7 +61,7 @@ module ApplicationTests assert_equal "https", ActionMailer::Base.default_url_options[:protocol] end - test "includes url helpers as action methods" do + test "includes URL helpers as action methods" do app_file "config/routes.rb", <<-RUBY Rails.application.routes.draw do get "/foo", :to => lambda { |env| [200, {}, []] }, :as => :foo diff --git a/railties/test/application/middleware/exceptions_test.rb b/railties/test/application/middleware/exceptions_test.rb index 2d659ade8d..17df78ed4e 100644 --- a/railties/test/application/middleware/exceptions_test.rb +++ b/railties/test/application/middleware/exceptions_test.rb @@ -60,7 +60,7 @@ module ApplicationTests assert_equal "YOU FAILED", last_response.body end - test "url generation error when action_dispatch.show_exceptions is set raises an exception" do + test "URL generation error when action_dispatch.show_exceptions is set raises an exception" do controller :foo, <<-RUBY class FooController < ActionController::Base def index diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index a1e237fa7b..258066a7e6 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -40,12 +40,12 @@ module ApplicationTests end end - test "db:create and db:drop without database url" do + test "db:create and db:drop without database URL" do require "#{app_path}/config/environment" db_create_and_drop ActiveRecord::Base.configurations[Rails.env]["database"] end - test "db:create and db:drop with database url" do + test "db:create and db:drop with database URL" do require "#{app_path}/config/environment" set_database_url db_create_and_drop database_url_db_name @@ -553,6 +553,22 @@ module ApplicationTests end end end + + test "db:prepare setup the database" do + Dir.chdir(app_path) do + rails "generate", "model", "book", "title:string" + output = rails("db:prepare") + assert_match(/CreateBooks: migrated/, output) + + output = rails("db:drop") + assert_match(/Dropped database/, output) + + rails "generate", "model", "recipe", "title:string" + output = rails("db:prepare") + assert_match(/CreateBooks: migrated/, output) + assert_match(/CreateRecipes: migrated/, output) + end + end end end end diff --git a/railties/test/application/rake/multi_dbs_test.rb b/railties/test/application/rake/multi_dbs_test.rb index d676e7486e..147b8f94e1 100644 --- a/railties/test/application/rake/multi_dbs_test.rb +++ b/railties/test/application/rake/multi_dbs_test.rb @@ -137,6 +137,21 @@ module ApplicationTests end end + def db_prepare + Dir.chdir(app_path) do + generate_models_for_animals + output = rails("db:prepare") + + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + if db_config.spec_name == "primary" + assert_match(/CreateBooks: migrated/, output) + else + assert_match(/CreateDogs: migrated/, output) + end + end + end + end + def write_models_for_animals # make a directory for the animals migration FileUtils.mkdir_p("#{app_path}/db/animals_migrate") @@ -226,6 +241,11 @@ module ApplicationTests require "#{app_path}/config/environment" db_migrate_and_schema_cache_dump_and_schema_cache_clear end + + test "db:prepare works on all databases" do + require "#{app_path}/config/environment" + db_prepare + end end end end diff --git a/railties/test/application/server_test.rb b/railties/test/application/server_test.rb index 9df36b3444..5fe1b4e6e7 100644 --- a/railties/test/application/server_test.rb +++ b/railties/test/application/server_test.rb @@ -30,13 +30,13 @@ module ApplicationTests pid = nil Bundler.with_original_env do - pid = Process.spawn("bin/rails server -P tmp/dummy.pid", chdir: app_path, in: replica, out: replica, err: replica) + pid = Process.spawn("bin/rails server -b localhost -P tmp/dummy.pid", chdir: app_path, in: replica, out: replica, err: replica) assert_output("Listening", primary) rails("restart") assert_output("Restarting", primary) - assert_output("Inherited", primary) + assert_output("tcp://localhost:3000", primary) ensure kill(pid) if pid end diff --git a/railties/test/application/zeitwerk_integration_test.rb b/railties/test/application/zeitwerk_integration_test.rb index c82b37d07d..dc6db429a9 100644 --- a/railties/test/application/zeitwerk_integration_test.rb +++ b/railties/test/application/zeitwerk_integration_test.rb @@ -124,12 +124,26 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase app_file "app/models/user.rb", "class User; end; $zeitwerk_integration_test_user = true" app_file "app/models/post.rb", "class Post; end; $zeitwerk_integration_test_post = true" + boot("production") assert $zeitwerk_integration_test_user assert $zeitwerk_integration_test_post end + test "eager loading loads code in engines" do + $test_blog_engine_eager_loaded = false + + engine("blog") do |bukkit| + bukkit.write("lib/blog.rb", "class BlogEngine < Rails::Engine; end") + bukkit.write("app/models/post.rb", "Post = $test_blog_engine_eager_loaded = true") + end + + boot("production") + + assert $test_blog_engine_eager_loaded + end + test "eager loading loads anything managed by Zeitwerk" do $zeitwerk_integration_test_user = false app_file "app/models/user.rb", "class User; end; $zeitwerk_integration_test_user = true" @@ -149,6 +163,34 @@ class ZeitwerkIntegrationTest < ActiveSupport::TestCase assert $zeitwerk_integration_test_extras end + test "autoload directories not present in eager load paths are not eager loaded" do + $zeitwerk_integration_test_user = false + app_file "app/models/user.rb", "class User; end; $zeitwerk_integration_test_user = true" + + $zeitwerk_integration_test_lib = false + app_dir "lib" + app_file "lib/webhook_hacks.rb", "WebhookHacks = 1; $zeitwerk_integration_test_lib = true" + + $zeitwerk_integration_test_extras = false + app_dir "extras" + app_file "extras/websocket_hacks.rb", "WebsocketHacks = 1; $zeitwerk_integration_test_extras = true" + + add_to_config "config.autoload_paths << '#{app_path}/lib'" + add_to_config "config.autoload_once_paths << '#{app_path}/extras'" + + boot("production") + + assert $zeitwerk_integration_test_user + assert_not $zeitwerk_integration_test_lib + assert_not $zeitwerk_integration_test_extras + + assert WebhookHacks + assert WebsocketHacks + + assert $zeitwerk_integration_test_lib + assert $zeitwerk_integration_test_extras + end + test "autoload_paths are set as root dirs of main, and in the same order" do boot diff --git a/railties/test/commands/console_test.rb b/railties/test/commands/console_test.rb index 1941c83d6d..f6df2b694a 100644 --- a/railties/test/commands/console_test.rb +++ b/railties/test/commands/console_test.rb @@ -129,7 +129,7 @@ class Rails::ConsoleTest < ActiveSupport::TestCase def build_app(console) mocked_console = Class.new do attr_accessor :sandbox - attr_reader :console + attr_reader :console, :disable_sandbox def initialize(console) @console = console diff --git a/railties/test/commands/credentials_test.rb b/railties/test/commands/credentials_test.rb index 3654e96aed..0ee36081c0 100644 --- a/railties/test/commands/credentials_test.rb +++ b/railties/test/commands/credentials_test.rb @@ -63,7 +63,7 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase end end - test "edit command properly expand environment option" do + test "edit command properly expands environment option" do assert_match(/access_key_id: 123/, run_edit_command(environment: "prod")) Dir.chdir(app_path) do assert File.exist?("config/credentials/production.key") @@ -79,11 +79,20 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase assert_match(/access_key_id: 123/, run_edit_command(environment: "qa")) end + test "edit command generates template file when the file does not exist" do + FileUtils.rm("#{app_path}/config/credentials.yml.enc") + run_edit_command + + output = run_show_command + assert_match(/access_key_id: 123/, output) + assert_match(/secret_key_base/, output) + end + test "show credentials" do assert_match(/access_key_id: 123/, run_show_command) end - test "show command raise error when require_master_key is specified and key does not exist" do + test "show command raises error when require_master_key is specified and key does not exist" do remove_file "config/master.key" add_to_config "config.require_master_key = true" @@ -103,10 +112,12 @@ class Rails::Command::CredentialsCommandTest < ActiveSupport::TestCase assert_match(/access_key_id: 123/, run_show_command(environment: "production")) end - test "show command properly expand environment option" do + test "show command properly expands environment option" do run_edit_command(environment: "production") - assert_match(/access_key_id: 123/, run_show_command(environment: "prod")) + output = run_show_command(environment: "prod") + assert_match(/access_key_id: 123/, output) + assert_no_match(/secret_key_base/, output) end private diff --git a/railties/test/commands/dbconsole_test.rb b/railties/test/commands/dbconsole_test.rb index 65f6916acb..76a7cd055f 100644 --- a/railties/test/commands/dbconsole_test.rb +++ b/railties/test/commands/dbconsole_test.rb @@ -216,22 +216,22 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end end - def test_specifying_a_custom_connection_and_environment + def test_specifying_a_custom_database_and_environment stub_available_environments(["development"]) do - dbconsole = parse_arguments(["-c", "custom", "-e", "development"]) + dbconsole = parse_arguments(["--db", "custom", "-e", "development"]) assert_equal "development", dbconsole[:environment] - assert_equal "custom", dbconsole.connection + assert_equal "custom", dbconsole.database end end - def test_specifying_a_missing_connection + def test_specifying_a_missing_database app_db_config({}) do e = assert_raises(ActiveRecord::AdapterNotSpecified) do - Rails::Command.invoke(:dbconsole, ["-c", "i_do_not_exist"]) + Rails::Command.invoke(:dbconsole, ["--db", "i_do_not_exist"]) end - assert_includes e.message, "'i_do_not_exist' connection is not configured." + assert_includes e.message, "'i_do_not_exist' database is not configured." end end @@ -245,6 +245,18 @@ class Rails::DBConsoleTest < ActiveSupport::TestCase end end + def test_connection_options_is_deprecate + command = Rails::Command::DbconsoleCommand.new([], ["-c", "custom"]) + Rails::DBConsole.stub(:start, nil) do + assert_deprecated("`connection` option is deprecated") do + command.perform + end + end + + assert_equal "custom", command.options["connection"] + assert_equal "custom", command.options["database"] + end + def test_print_help_short stdout = capture(:stdout) do Rails::Command.invoke(:dbconsole, ["-h"]) diff --git a/railties/test/generators/app_generator_test.rb b/railties/test/generators/app_generator_test.rb index 1ee9e43e89..3bdbc70990 100644 --- a/railties/test/generators/app_generator_test.rb +++ b/railties/test/generators/app_generator_test.rb @@ -526,7 +526,7 @@ class AppGeneratorTest < Rails::Generators::TestCase if defined?(JRUBY_VERSION) assert_gem "activerecord-jdbcsqlite3-adapter" else - assert_gem "sqlite3", "'~> 1.3', '>= 1.3.6'" + assert_gem "sqlite3", "'~> 1.4'" end end @@ -617,7 +617,7 @@ class AppGeneratorTest < Rails::Generators::TestCase assert_no_gem "capybara" assert_no_gem "selenium-webdriver" - assert_no_gem "chromedriver-helper" + assert_no_gem "webdrivers" assert_no_directory("test") end @@ -626,7 +626,7 @@ class AppGeneratorTest < Rails::Generators::TestCase run_generator [destination_root, "--skip-system-test"] assert_no_gem "capybara" assert_no_gem "selenium-webdriver" - assert_no_gem "chromedriver-helper" + assert_no_gem "webdrivers" assert_directory("test") @@ -678,6 +678,21 @@ class AppGeneratorTest < Rails::Generators::TestCase end end + def test_inclusion_of_listen_related_configuration_on_other_rubies + ruby_engine = Object.send(:remove_const, :RUBY_ENGINE) + Object.const_set(:RUBY_ENGINE, "MyRuby") + + run_generator + if RbConfig::CONFIG["host_os"] =~ /darwin|linux/ + assert_listen_related_configuration + else + assert_no_listen_related_configuration + end + ensure + Object.send(:remove_const, :RUBY_ENGINE) + Object.const_set(:RUBY_ENGINE, ruby_engine) + end + def test_non_inclusion_of_listen_related_configuration_if_skip_listen run_generator [destination_root, "--skip-listen"] assert_no_listen_related_configuration @@ -968,6 +983,8 @@ class AppGeneratorTest < Rails::Generators::TestCase else assert_match(/#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}/, content) end + + assert content.end_with?("\n"), "expected .ruby-version to end with newline" end end diff --git a/railties/test/generators/db_system_change_generator_test.rb b/railties/test/generators/db_system_change_generator_test.rb index d3d27b616a..607db96906 100644 --- a/railties/test/generators/db_system_change_generator_test.rb +++ b/railties/test/generators/db_system_change_generator_test.rb @@ -68,7 +68,7 @@ module Rails assert_file("Gemfile") do |content| assert_match "# Use sqlite3 as the database for Active Record", content - assert_match "gem 'sqlite3', '~> 1.3', '>= 1.3.6'", content + assert_match "gem 'sqlite3', '~> 1.4'", content end end diff --git a/railties/test/generators/generated_attribute_test.rb b/railties/test/generators/generated_attribute_test.rb index 772b4f6f0d..bf60d6bc22 100644 --- a/railties/test/generators/generated_attribute_test.rb +++ b/railties/test/generators/generated_attribute_test.rb @@ -38,6 +38,16 @@ class GeneratedAttributeTest < Rails::Generators::TestCase assert_field_type :boolean, :check_box end + def test_field_type_returns_rich_text_area + assert_field_type :rich_text, :rich_text_area + end + + def test_field_type_returns_file_field + %w(attachment attachments).each do |attribute_type| + assert_field_type attribute_type, :file_field + end + end + def test_field_type_with_unknown_type_returns_text_field %w(foo bar baz).each do |attribute_type| assert_field_type attribute_type, :text_field @@ -84,7 +94,7 @@ class GeneratedAttributeTest < Rails::Generators::TestCase end def test_default_value_is_nil - %w(references belongs_to).each do |attribute_type| + %w(references belongs_to rich_text attachment attachments).each do |attribute_type| assert_field_default_value attribute_type, nil end end diff --git a/railties/test/generators/migration_generator_test.rb b/railties/test/generators/migration_generator_test.rb index 5812cbdfc9..540bed551b 100644 --- a/railties/test/generators/migration_generator_test.rb +++ b/railties/test/generators/migration_generator_test.rb @@ -265,6 +265,17 @@ class MigrationGeneratorTest < Rails::Generators::TestCase end end + def test_database_puts_migrations_in_configured_folder_with_aliases + with_secondary_database_configuration do + run_generator ["create_books", "--db=secondary"] + assert_migration "db/secondary_migrate/create_books.rb" do |content| + assert_method :change, content do |change| + assert_match(/create_table :books/, change) + end + end + end + end + def test_should_create_empty_migrations_if_name_not_start_with_add_or_remove_or_create migration = "delete_books" run_generator [migration, "title:string", "content:text"] @@ -355,6 +366,44 @@ class MigrationGeneratorTest < Rails::Generators::TestCase Rails.application.config.paths["db/migrate"] = old_paths end + def test_add_migration_ignores_virtual_attributes + migration = "add_rich_text_content_to_messages" + run_generator [migration, "content:rich_text", "video:attachment", "photos:attachments"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |change| + assert_no_match(/add_column :messages, :content, :rich_text/, change) + assert_no_match(/add_column :messages, :video, :attachment/, change) + assert_no_match(/add_column :messages, :photos, :attachments/, change) + end + end + end + + def test_create_table_migration_ignores_virtual_attributes + run_generator ["create_messages", "content:rich_text", "video:attachment", "photos:attachments"] + assert_migration "db/migrate/create_messages.rb" do |content| + assert_method :change, content do |change| + assert_match(/create_table :messages/, change) + assert_no_match(/ t\.rich_text :content/, change) + assert_no_match(/ t\.attachment :video/, change) + assert_no_match(/ t\.attachments :photos/, change) + end + end + end + + def test_remove_migration_with_virtual_attributes + migration = "remove_content_from_messages" + run_generator [migration, "content:rich_text", "video:attachment", "photos:attachments"] + + assert_migration "db/migrate/#{migration}.rb" do |content| + assert_method :change, content do |change| + assert_no_match(/remove_column :messages, :content, :rich_text/, change) + assert_no_match(/remove_column :messages, :video, :attachment/, change) + assert_no_match(/remove_column :messages, :photos, :attachments/, change) + end + end + end + private def with_singular_table_name diff --git a/railties/test/generators/model_generator_test.rb b/railties/test/generators/model_generator_test.rb index 134659f285..c97cd17ec6 100644 --- a/railties/test/generators/model_generator_test.rb +++ b/railties/test/generators/model_generator_test.rb @@ -403,6 +403,17 @@ class ModelGeneratorTest < Rails::Generators::TestCase end end + def test_database_puts_migrations_in_configured_folder_with_aliases + with_secondary_database_configuration do + run_generator ["account", "--db=secondary"] + assert_migration "db/secondary_migrate/create_accounts.rb" do |content| + assert_method :change, content do |change| + assert_match(/create_table :accounts/, change) + end + end + end + end + def test_required_belongs_to_adds_required_association run_generator ["account", "supplier:references{required}"] @@ -488,6 +499,43 @@ class ModelGeneratorTest < Rails::Generators::TestCase assert_file "app/models/user.rb", expected_file end + def test_model_with_rich_text_attribute_adds_has_rich_text + run_generator ["message", "content:rich_text"] + expected_file = <<~FILE + class Message < ApplicationRecord + has_rich_text :content + end + FILE + assert_file "app/models/message.rb", expected_file + end + + def test_model_with_attachment_attribute_adds_has_one_attached + run_generator ["message", "video:attachment"] + expected_file = <<~FILE + class Message < ApplicationRecord + has_one_attached :video + end + FILE + assert_file "app/models/message.rb", expected_file + end + + def test_model_with_attachments_attribute_adds_has_many_attached + run_generator ["message", "photos:attachments"] + expected_file = <<~FILE + class Message < ApplicationRecord + has_many_attached :photos + end + FILE + assert_file "app/models/message.rb", expected_file + end + + def test_skip_virtual_fields_in_fixtures + run_generator ["message", "content:rich_text", "video:attachment", "photos:attachments"] + + assert_generated_fixture("test/fixtures/messages.yml", + "one" => nil, "two" => nil) + end + private def assert_generated_fixture(path, parsed_contents) fixture_file = File.new File.expand_path(path, destination_root) diff --git a/railties/test/generators/scaffold_controller_generator_test.rb b/railties/test/generators/scaffold_controller_generator_test.rb index fd5aa817b4..1348744b0b 100644 --- a/railties/test/generators/scaffold_controller_generator_test.rb +++ b/railties/test/generators/scaffold_controller_generator_test.rb @@ -80,6 +80,15 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase end end + def test_controller_permit_attachment_attributes + run_generator ["Message", "video:attachment", "photos:attachments"] + + assert_file "app/controllers/messages_controller.rb" do |content| + assert_match(/def message_params/, content) + assert_match(/params\.require\(:message\)\.permit\(:video, photos: \[\]\)/, content) + end + end + def test_helper_are_invoked_with_a_pluralized_name run_generator assert_file "app/helpers/users_helper.rb", /module UsersHelper/ @@ -276,4 +285,13 @@ class ScaffoldControllerGeneratorTest < Rails::Generators::TestCase assert_no_match(/assert_redirected_to/, content) end end + + def test_api_only_generates_params_for_attachments + run_generator ["Message", "video:attachment", "photos:attachments", "--api"] + + assert_file "app/controllers/messages_controller.rb" do |content| + assert_match(/def message_params/, content) + assert_match(/params\.require\(:message\)\.permit\(:video, photos: \[\]\)/, content) + end + end end diff --git a/railties/test/generators/scaffold_generator_test.rb b/railties/test/generators/scaffold_generator_test.rb index f672e301a7..bfa52a1beb 100644 --- a/railties/test/generators/scaffold_generator_test.rb +++ b/railties/test/generators/scaffold_generator_test.rb @@ -471,6 +471,24 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end + def test_scaffold_generator_attachments + run_generator ["message", "video:attachment", "photos:attachments", "images:attachments"] + + assert_file "app/models/message.rb", /has_one_attached :video/ + assert_file "app/models/message.rb", /has_many_attached :photos/ + + assert_file "app/controllers/messages_controller.rb" do |content| + assert_instance_method :message_params, content do |m| + assert_match(/permit\(:video, photos: \[\], images: \[\]\)/, m) + end + end + + assert_file "app/views/messages/_form.html.erb" do |content| + assert_match(/^\W{4}<%= form\.file_field :video %>/, content) + assert_match(/^\W{4}<%= form\.file_field :photos, multiple: true %>/, content) + end + end + def test_scaffold_generator_database with_secondary_database_configuration do run_generator ["posts", "--database=secondary"] @@ -479,6 +497,14 @@ class ScaffoldGeneratorTest < Rails::Generators::TestCase end end + def test_scaffold_generator_database_with_aliases + with_secondary_database_configuration do + run_generator ["posts", "--db=secondary"] + + assert_migration "db/secondary_migrate/create_posts.rb" + end + end + def test_scaffold_generator_password_digest run_generator ["user", "name", "password:digest"] diff --git a/railties/test/isolation/abstract_unit.rb b/railties/test/isolation/abstract_unit.rb index 14cdf1ab7c..3fcfaa9623 100644 --- a/railties/test/isolation/abstract_unit.rb +++ b/railties/test/isolation/abstract_unit.rb @@ -123,6 +123,8 @@ module TestHelpers adapter: sqlite3 pool: 5 timeout: 5000 + variables: + statement_timeout: 1000 development: primary: <<: *default |