aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2018-09-22 00:46:44 -0400
committerRafael Mendonça França <rafaelmfranca@gmail.com>2018-09-22 00:46:44 -0400
commitd3b952184d8bdb6154aff1f8bc3eda58046026f6 (patch)
treeb49246fa36ee850ef6a56ce01ec4322349ffff45 /railties/test
parentb18f2fe96debdcd0744f99101d1a1e0d42c41eaa (diff)
downloadrails-d3b952184d8bdb6154aff1f8bc3eda58046026f6.tar.gz
rails-d3b952184d8bdb6154aff1f8bc3eda58046026f6.tar.bz2
rails-d3b952184d8bdb6154aff1f8bc3eda58046026f6.zip
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".
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/rake/dbs_test.rb18
1 files changed, 12 insertions, 6 deletions
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