aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/application/rake/dbs_test.rb
diff options
context:
space:
mode:
authoreileencodes <eileencodes@gmail.com>2019-03-05 18:45:06 -0500
committereileencodes <eileencodes@gmail.com>2019-03-06 08:59:27 -0500
commit37d1429ab1da78a3b8afcfcec8a135ac85cd897a (patch)
tree74d6f9dd0ffe5bb3c6ac5366cba918da63f5e903 /railties/test/application/rake/dbs_test.rb
parentdb94f492c099db89746f945a522aa7e59ede97cb (diff)
downloadrails-37d1429ab1da78a3b8afcfcec8a135ac85cd897a.tar.gz
rails-37d1429ab1da78a3b8afcfcec8a135ac85cd897a.tar.bz2
rails-37d1429ab1da78a3b8afcfcec8a135ac85cd897a.zip
Load YAML for rake tasks without parsing ERB
This change adds a new method that loads the YAML for the database config without parsing the ERB. This may seem odd but bear with me: When we added the ability to have rake tasks for multiple databases we started looping through the configurations to collect the namespaces so we could do `rake db:create:my_second_db`. See #32274. This caused a problem where if you had `Rails.config.max_threads` set in your database.yml it will blow up because the environment that defines `max_threads` isn't loaded during `rake -T`. See #35468. We tried to fix this by adding the ability to just load the YAML and ignore ERB all together but that caused a bug in GitHub's YAML loading where if you used multi-line ERB the YAML was invalid. That led us to reverting some changes in #33748. After trying to resolve this a bunch of ways `@tenderlove` came up with replacing the ERB values so that we don't need to load the environment but we also can load the YAML. This change adds a DummyCompiler for ERB that will replace all the values so we can load the database yaml and create the rake tasks. Nothing else uses this method so it's "safe". DO NOT use this method in your application. Fixes #35468
Diffstat (limited to 'railties/test/application/rake/dbs_test.rb')
-rw-r--r--railties/test/application/rake/dbs_test.rb15
1 files changed, 3 insertions, 12 deletions
diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb
index a8ec1f3663..07d57dea8a 100644
--- a/railties/test/application/rake/dbs_test.rb
+++ b/railties/test/application/rake/dbs_test.rb
@@ -54,26 +54,17 @@ module ApplicationTests
test "db:create and db:drop respect environment setting" do
app_file "config/database.yml", <<-YAML
development:
- database: db/development.sqlite3
+ database: <%= Rails.application.config.database %>
adapter: sqlite3
YAML
app_file "config/environments/development.rb", <<-RUBY
Rails.application.configure do
- config.read_encrypted_secrets = true
+ config.database = "db/development.sqlite3"
end
RUBY
- 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", environment_loaded: false) do
- assert File.exist?("tmp/config_value")
- assert_equal "true", File.read("tmp/config_value")
- end
+ db_create_and_drop("db/development.sqlite3", environment_loaded: false)
end
def with_database_existing