Skip to content

Commit d3b9521

Browse files
committed
Make sure this test check the issue solved in rails#31135
Before this change this test was passing even if we revert rails#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".
1 parent b18f2fe commit d3b9521

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

railties/test/application/rake/dbs_test.rb

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ def set_database_url
2626
FileUtils.rm_rf("#{app_path}/config/database.yml")
2727
end
2828

29-
def db_create_and_drop(expected_database)
29+
def db_create_and_drop(expected_database, environment_loaded: true)
3030
Dir.chdir(app_path) do
3131
output = rails("db:create")
3232
assert_match(/Created database/, output)
3333
assert File.exist?(expected_database)
34-
assert_equal expected_database, ActiveRecord::Base.connection_config[:database]
34+
yield if block_given?
35+
assert_equal expected_database, ActiveRecord::Base.connection_config[:database] if environment_loaded
3536
output = rails("db:drop")
3637
assert_match(/Dropped database/, output)
3738
assert_not File.exist?(expected_database)
@@ -62,11 +63,16 @@ def db_create_and_drop(expected_database)
6263
end
6364
RUBY
6465

65-
app "development"
66-
67-
assert_equal true, Rails.application.config.read_encrypted_secrets
66+
app_file "lib/tasks/check_env.rake", <<-RUBY
67+
Rake::Task["db:create"].enhance do
68+
File.write("tmp/config_value", Rails.application.config.read_encrypted_secrets)
69+
end
70+
RUBY
6871

69-
db_create_and_drop "db/development.sqlite3"
72+
db_create_and_drop("db/development.sqlite3", environment_loaded: false) do
73+
assert File.exist?("tmp/config_value")
74+
assert_equal "true", File.read("tmp/config_value")
75+
end
7076
end
7177

7278
def with_database_existing

0 commit comments

Comments
 (0)