diff options
Diffstat (limited to 'railties/test/application')
-rw-r--r-- | railties/test/application/configuration_test.rb | 9 | ||||
-rw-r--r-- | railties/test/application/rake/dbs_test.rb | 16 | ||||
-rw-r--r-- | railties/test/application/rake/dev_test.rb | 44 | ||||
-rw-r--r-- | railties/test/application/rake/initializers_test.rb | 44 | ||||
-rw-r--r-- | railties/test/application/rake/multi_dbs_test.rb | 27 | ||||
-rw-r--r-- | railties/test/application/rake/notes_test.rb | 1 | ||||
-rw-r--r-- | railties/test/application/rake/routes_test.rb | 43 |
7 files changed, 151 insertions, 33 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb index c2699006f6..f5119b1931 100644 --- a/railties/test/application/configuration_test.rb +++ b/railties/test/application/configuration_test.rb @@ -1996,6 +1996,15 @@ module ApplicationTests assert_equal false, ActionView::Template.finalize_compiled_template_methods end + test "ActiveRecord::Base.filter_attributes should equal to filter_parameters" do + app_file "config/initializers/filter_parameters_logging.rb", <<-RUBY + Rails.application.config.filter_parameters += [ :password, :credit_card_number ] + RUBY + app "development" + assert_equal [ :password, :credit_card_number ], Rails.application.config.filter_parameters + assert_equal [ :password, :credit_card_number ], ActiveRecord::Base.filter_attributes + 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/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 0594236b1f..b1038ba5d6 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -26,12 +26,12 @@ module ApplicationTests FileUtils.rm_rf("#{app_path}/config/database.yml") end - def db_create_and_drop(expected_database, environment_loaded: true) + def db_create_and_drop(expected_database) Dir.chdir(app_path) do output = rails("db:create") assert_match(/Created database/, output) assert File.exist?(expected_database) - assert_equal expected_database, ActiveRecord::Base.connection_config[:database] if environment_loaded + assert_equal expected_database, ActiveRecord::Base.connection_config[:database] output = rails("db:drop") assert_match(/Dropped database/, output) assert_not File.exist?(expected_database) @@ -52,17 +52,21 @@ module ApplicationTests test "db:create and db:drop respect environment setting" do app_file "config/database.yml", <<-YAML development: - database: <%= Rails.application.config.database %> + database: db/development.sqlite3 adapter: sqlite3 YAML app_file "config/environments/development.rb", <<-RUBY Rails.application.configure do - config.database = "db/development.sqlite3" + config.read_encrypted_secrets = true end RUBY - db_create_and_drop "db/development.sqlite3", environment_loaded: false + app "development" + + assert_equal true, Rails.application.config.read_encrypted_secrets + + db_create_and_drop "db/development.sqlite3" end def with_database_existing @@ -93,7 +97,7 @@ module ApplicationTests test "db:create failure because bad permissions" do with_bad_permissions do output = rails("db:create", allow_failure: true) - assert_match(/Couldn't create database/, output) + assert_match("Couldn't create '#{database_url_db_name}' database. Please check your configuration.", output) assert_equal 1, $?.exitstatus end end diff --git a/railties/test/application/rake/dev_test.rb b/railties/test/application/rake/dev_test.rb index 66e1ac9d99..a87f453075 100644 --- a/railties/test/application/rake/dev_test.rb +++ b/railties/test/application/rake/dev_test.rb @@ -9,6 +9,7 @@ module ApplicationTests def setup build_app + add_to_env_config("development", "config.active_support.deprecation = :stderr") end def teardown @@ -17,33 +18,46 @@ module ApplicationTests test "dev:cache creates file and outputs message" do Dir.chdir(app_path) do - output = rails("dev:cache") - assert File.exist?("tmp/caching-dev.txt") - assert_match(/Development mode is now being cached/, output) + stderr = capture(:stderr) do + output = run_rake_dev_cache + assert File.exist?("tmp/caching-dev.txt") + assert_match(/Development mode is now being cached/, output) + end + assert_match(/DEPRECATION WARNING: Using `bin\/rake dev:cache` is deprecated and will be removed in Rails 6.1/, stderr) end end test "dev:cache deletes file and outputs message" do Dir.chdir(app_path) do - rails "dev:cache" # Create caching file. - output = rails("dev:cache") # Delete caching file. - assert_not File.exist?("tmp/caching-dev.txt") - assert_match(/Development mode is no longer being cached/, output) + stderr = capture(:stderr) do + run_rake_dev_cache # Create caching file. + output = run_rake_dev_cache # Delete caching file. + assert_not File.exist?("tmp/caching-dev.txt") + assert_match(/Development mode is no longer being cached/, output) + end + assert_match(/DEPRECATION WARNING: Using `bin\/rake dev:cache` is deprecated and will be removed in Rails 6.1/, stderr) end end test "dev:cache touches tmp/restart.txt" do Dir.chdir(app_path) do - rails "dev:cache" - assert File.exist?("tmp/restart.txt") - - prev_mtime = File.mtime("tmp/restart.txt") - sleep(1) - rails "dev:cache" - curr_mtime = File.mtime("tmp/restart.txt") - assert_not_equal prev_mtime, curr_mtime + stderr = capture(:stderr) do + run_rake_dev_cache + assert File.exist?("tmp/restart.txt") + + prev_mtime = File.mtime("tmp/restart.txt") + run_rake_dev_cache + curr_mtime = File.mtime("tmp/restart.txt") + assert_not_equal prev_mtime, curr_mtime + end + assert_match(/DEPRECATION WARNING: Using `bin\/rake dev:cache` is deprecated and will be removed in Rails 6.1/, stderr) end end + + private + def run_rake_dev_cache + `bin/rake dev:cache` + end end end end diff --git a/railties/test/application/rake/initializers_test.rb b/railties/test/application/rake/initializers_test.rb new file mode 100644 index 0000000000..8de4967021 --- /dev/null +++ b/railties/test/application/rake/initializers_test.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require "isolation/abstract_unit" + +module ApplicationTests + module RakeTests + class RakeInitializersTest < ActiveSupport::TestCase + setup :build_app + teardown :teardown_app + + test "`rake initializers` prints out defined initializers invoked by Rails" do + capture(:stderr) do + initial_output = run_rake_initializers + initial_output_length = initial_output.split("\n").length + + assert_operator initial_output_length, :>, 0 + assert_not initial_output.include?("set_added_test_module") + + add_to_config <<-RUBY + initializer(:set_added_test_module) { } + RUBY + + final_output = run_rake_initializers + final_output_length = final_output.split("\n").length + + assert_equal 1, (final_output_length - initial_output_length) + assert final_output.include?("set_added_test_module") + end + end + + test "`rake initializers` outputs a deprecation warning" do + add_to_env_config("development", "config.active_support.deprecation = :stderr") + + stderr = capture(:stderr) { run_rake_initializers } + assert_match(/DEPRECATION WARNING: Using `bin\/rake initializers` is deprecated and will be removed in Rails 6.1/, stderr) + end + + private + def run_rake_initializers + Dir.chdir(app_path) { `bin/rake initializers` } + 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 07d96fcb56..bc6708c89e 100644 --- a/railties/test/application/rake/multi_dbs_test.rb +++ b/railties/test/application/rake/multi_dbs_test.rb @@ -16,21 +16,24 @@ module ApplicationTests teardown_app end - def db_create_and_drop(namespace, expected_database, environment_loaded: true) + def db_create_and_drop(namespace, expected_database) Dir.chdir(app_path) do output = rails("db:create") assert_match(/Created database/, output) assert_match_namespace(namespace, output) + assert_no_match(/already exists/, output) assert File.exist?(expected_database) + output = rails("db:drop") assert_match(/Dropped database/, output) assert_match_namespace(namespace, output) + assert_no_match(/does not exist/, output) assert_not File.exist?(expected_database) end end - def db_create_and_drop_namespace(namespace, expected_database, environment_loaded: true) + def db_create_and_drop_namespace(namespace, expected_database) Dir.chdir(app_path) do output = rails("db:create:#{namespace}") assert_match(/Created database/, output) @@ -127,36 +130,36 @@ EOS test "db:create and db:drop works on all databases for env" do require "#{app_path}/config/environment" - ActiveRecord::Base.configurations[Rails.env].each do |namespace, config| - db_create_and_drop namespace, config["database"] + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + db_create_and_drop db_config.spec_name, db_config.config["database"] end end test "db:create:namespace and db:drop:namespace works on specified databases" do require "#{app_path}/config/environment" - ActiveRecord::Base.configurations[Rails.env].each do |namespace, config| - db_create_and_drop_namespace namespace, config["database"] + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + db_create_and_drop_namespace db_config.spec_name, db_config.config["database"] end end test "db:migrate and db:schema:dump and db:schema:load works on all databases" do require "#{app_path}/config/environment" - ActiveRecord::Base.configurations[Rails.env].each do |namespace, config| - db_migrate_and_schema_dump_and_load namespace, config["database"], "schema" + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + db_migrate_and_schema_dump_and_load db_config.spec_name, db_config.config["database"], "schema" end end test "db:migrate and db:structure:dump and db:structure:load works on all databases" do require "#{app_path}/config/environment" - ActiveRecord::Base.configurations[Rails.env].each do |namespace, config| - db_migrate_and_schema_dump_and_load namespace, config["database"], "structure" + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + db_migrate_and_schema_dump_and_load db_config.spec_name, db_config.config["database"], "structure" end end test "db:migrate:namespace works" do require "#{app_path}/config/environment" - ActiveRecord::Base.configurations[Rails.env].each do |namespace, config| - db_migrate_namespaced namespace, config["database"] + ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).each do |db_config| + db_migrate_namespaced db_config.spec_name, db_config.config["database"] end end end diff --git a/railties/test/application/rake/notes_test.rb b/railties/test/application/rake/notes_test.rb index 9e22ba84b5..60802ef7c4 100644 --- a/railties/test/application/rake/notes_test.rb +++ b/railties/test/application/rake/notes_test.rb @@ -10,6 +10,7 @@ module ApplicationTests def setup build_app + add_to_env_config("development", "config.active_support.deprecation = :stderr") require "rails/all" super end diff --git a/railties/test/application/rake/routes_test.rb b/railties/test/application/rake/routes_test.rb new file mode 100644 index 0000000000..2c23ff4679 --- /dev/null +++ b/railties/test/application/rake/routes_test.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require "isolation/abstract_unit" + +module ApplicationTests + module RakeTests + class RakeRoutesTest < ActiveSupport::TestCase + include ActiveSupport::Testing::Isolation + setup :build_app + teardown :teardown_app + + test "`rake routes` outputs routes" do + app_file "config/routes.rb", <<-RUBY + Rails.application.routes.draw do + get '/cart', to: 'cart#show' + end + RUBY + + assert_equal <<~MESSAGE, run_rake_routes + Prefix Verb URI Pattern Controller#Action + cart GET /cart(.:format) cart#show + rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show +rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show + rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show +update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update + rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format) active_storage/direct_uploads#create + MESSAGE + end + + test "`rake routes` outputs a deprecation warning" do + add_to_env_config("development", "config.active_support.deprecation = :stderr") + + stderr = capture(:stderr) { run_rake_routes } + assert_match(/DEPRECATION WARNING: Using `bin\/rake routes` is deprecated and will be removed in Rails 6.1/, stderr) + end + + private + def run_rake_routes + Dir.chdir(app_path) { `bin/rake routes` } + end + end + end +end |