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".
上级 b18f2fe9
......@@ -26,12 +26,13 @@ def set_database_url
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 @@ def db_create_and_drop(expected_database)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册