mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #33748 from eileencodes/fix-erb-loading-issue-with-db-yaml
Drop load_database_yaml and fix test
This commit is contained in:
commit
55133a0e8e
3 changed files with 8 additions and 16 deletions
|
@ -135,7 +135,7 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def for_each
|
||||
databases = Rails.application.config.load_database_yaml
|
||||
databases = Rails.application.config.database_configuration
|
||||
database_configs = ActiveRecord::DatabaseConfigurations.configs_for(Rails.env, databases)
|
||||
|
||||
# if this is a single database application we don't want tasks for each primary database
|
||||
|
|
|
@ -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 <tt>config/database.yml</tt>.
|
||||
def database_configuration
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue