From 6b5df90fb56d86f0cd04a27a94dfe876e21fa001 Mon Sep 17 00:00:00 2001 From: Eileen Uchitelle Date: Wed, 29 Aug 2018 10:26:44 -0400 Subject: Drop load_database_yaml and fix test We originally did the whole `load_database_yaml` thing because this test wasn't cooperating and we needed to finish the namespaced rake tasks for multiple databases. However, it turns out that YAML can't eval ERB if you don't tell it it's ERB so you get Pysch parse errors if you're using multi-line ERB or ERB with conditionals. It's a hot mess. After trying a few things and thinking it over we decided that it wasn't worth bandaiding over, the test needed to be improved. The test was added in #31135 to test that the env is loaded in these tasks. But it was blowing up because we were trying to read a database name out of the configuration - however that's not the purpose of this change. We want to read environment files in the rake tasks, but not in the config file. In this PR we changed the test to test what the PR was actually fixing. We've also deleted the `load_database_yaml` because it caused more problems than it was worth. This should fix the issues described in https://github.com/rails/rails/pull/32274#issuecomment-384161057. We also had these problems at GitHub. Co-authored-by: alimi --- railties/lib/rails/application/configuration.rb | 12 ------------ railties/test/application/rake/dbs_test.rb | 10 +++++++--- 2 files changed, 7 insertions(+), 15 deletions(-) (limited to 'railties') diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index 9eb07219e0..f4cbd2b9d0 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -168,18 +168,6 @@ module Rails end end - # Loads the database YAML without evaluating ERB. People seem to - # write ERB that makes the database configuration depend on - # Rails configuration. But we want Rails configuration (specifically - # `rake` and `rails` tasks) to be generated based on information in - # the database yaml, so we need a method that loads the database - # yaml *without* the context of the Rails application. - def load_database_yaml # :nodoc: - path = paths["config/database"].existent.first - return {} unless path - YAML.load_file(path.to_s) - end - # Loads and returns the entire raw configuration of database from # values stored in config/database.yml. def database_configuration diff --git a/railties/test/application/rake/dbs_test.rb b/railties/test/application/rake/dbs_test.rb index 0594236b1f..5dbdd669d6 100644 --- a/railties/test/application/rake/dbs_test.rb +++ b/railties/test/application/rake/dbs_test.rb @@ -52,17 +52,21 @@ module ApplicationTests test "db:create and db:drop respect environment setting" do app_file "config/database.yml", <<-YAML development: - database: <%= Rails.application.config.database %> + database: db/development.sqlite3 adapter: sqlite3 YAML app_file "config/environments/development.rb", <<-RUBY Rails.application.configure do - config.database = "db/development.sqlite3" + config.read_encrypted_secrets = true end RUBY - db_create_and_drop "db/development.sqlite3", environment_loaded: false + app "development" + + assert_equal true, Rails.application.config.read_encrypted_secrets + + db_create_and_drop "db/development.sqlite3" end def with_database_existing -- cgit v1.2.3