From d3b952184d8bdb6154aff1f8bc3eda58046026f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Sat, 22 Sep 2018 00:46:44 -0400 Subject: Make sure this test check the issue solved in #31135 Before this change this test was passing even if we revert #31135. The reason for that is that `app 'development'` will load the environment in the test process and it is happening before db_create_and_drop is called. This was not asserting that the environment was loaded in the db:create task itself. To test it we enhance the db:create task with a block that writes to a tmp file the value of the config. If the environment is loaded before that task enhancement runs the content of the file will have "true" insteand of "false". --- railties/test/application/rake/dbs_test.rb | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'railties/test') diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index b1038ba5d6..039987ac8c 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -26,12 +26,13 @@ module ApplicationTests FileUtils.rm_rf("#{app_path}/config/database.yml") end - def db_create_and_drop(expected_database) + def db_create_and_drop(expected_database, environment_loaded: true) 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] + yield if block_given? + assert_equal expected_database, ActiveRecord::Base.connection_config[:database] if environment_loaded output = rails("db:drop") assert_match(/Dropped database/, output) assert_not File.exist?(expected_database) @@ -62,11 +63,16 @@ module ApplicationTests end RUBY - app "development" - - assert_equal true, Rails.application.config.read_encrypted_secrets + app_file "lib/tasks/check_env.rake", <<-RUBY + Rake::Task["db:create"].enhance do + File.write("tmp/config_value", Rails.application.config.read_encrypted_secrets) + end + RUBY - db_create_and_drop "db/development.sqlite3" + db_create_and_drop("db/development.sqlite3", environment_loaded: false) do + assert File.exist?("tmp/config_value") + assert_equal "true", File.read("tmp/config_value") + end end def with_database_existing -- cgit v1.2.3