1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge shared configuration deeply

This commit is contained in:
kirikiriyamama 2019-12-08 22:11:14 +09:00
parent b4ee2d5f65
commit 4d858b3f2a
2 changed files with 22 additions and 1 deletions

View file

@ -229,7 +229,7 @@ module Rails
if yaml.exist?
require "erb"
config = YAML.load(ERB.new(yaml.read).result, symbolize_names: true) || {}
config = (config[:shared] || {}).merge(config[env.to_sym] || {})
config = (config[:shared] || {}).deep_merge(config[env.to_sym] || {})
ActiveSupport::OrderedOptions.new.tap do |options|
options.update(config)

View file

@ -2034,6 +2034,27 @@ module ApplicationTests
assert_equal(:bar, Rails.application.config.my_custom_config[:foo])
end
test "config_for merges shared configuration deeply" do
app_file "config/custom.yml", <<-RUBY
shared:
foo:
bar:
baz: 1
development:
foo:
bar:
qux: 2
RUBY
add_to_config <<-RUBY
config.my_custom_config = config_for('custom')
RUBY
app "development"
assert_equal({ baz: 1, qux: 2 }, Rails.application.config.my_custom_config[:foo][:bar])
end
test "config_for with empty file returns an empty hash" do
app_file "config/custom.yml", <<-RUBY
RUBY