Skip to content

Commit

Permalink
Merge pull request #47431 from skipkayhil/make-shared-three-tier-aware
Browse files Browse the repository at this point in the history
Allow 3-tier shared config in database.yml
  • Loading branch information
eileencodes committed Feb 22, 2023
2 parents 3886edc + 0401f50 commit 0cbc50a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
10 changes: 8 additions & 2 deletions railties/lib/rails/application/configuration.rb
Expand Up @@ -417,8 +417,14 @@ def database_configuration
if (shared = loaded_yaml.delete("shared"))
loaded_yaml.each do |env, config|
if config.is_a?(Hash) && config.values.all?(Hash)
config.map do |name, sub_config|
sub_config.reverse_merge!(shared)
if shared.is_a?(Hash) && shared.values.all?(Hash)
config.map do |name, sub_config|
sub_config.reverse_merge!(shared[name])
end
else
config.map do |name, sub_config|
sub_config.reverse_merge!(shared)
end
end
else
config.reverse_merge!(shared)
Expand Down
22 changes: 22 additions & 0 deletions railties/test/application/configuration_test.rb
Expand Up @@ -2180,6 +2180,28 @@ def index
assert_equal "dev_db", ar_config["development"]["primary"]["database"]
end

test "loads database.yml using 3-tier shared keys with a 3-tier config" do
app_file "config/database.yml", <<-YAML
shared:
one:
migrations_path: "db/one"
two:
migrations_path: "db/two"
development:
one:
adapter: sqlite3
two:
adapter: sqlite3
YAML

app "development"

ar_config = Rails.configuration.database_configuration
assert_equal "db/one", ar_config["development"]["one"]["migrations_path"]
assert_equal "db/two", ar_config["development"]["two"]["migrations_path"]
end

test "config.action_mailer.show_previews defaults to true in development" do
app "development"

Expand Down

0 comments on commit 0cbc50a

Please sign in to comment.