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

config_for accepts root shared as an array

Fix a bug introduced by
3fe0ab52df
that raised an undefined method when trying to deep merge an array with
an empty config hash

It also adds a test to clarify config_for behaviour with root arrays: when there's
an env array and a shared array, it should only returns the env key (and not a concatenation)

Closes #42698
This commit is contained in:
Loïc Delmaire 2021-07-06 11:35:04 +02:00
parent 398561bfbb
commit 056b70ee4f
No known key found for this signature in database
GPG key ID: 44D18BC81F983E1D
3 changed files with 34 additions and 2 deletions

View file

@ -1,3 +1,7 @@
* Fix `config_for` error when there's only a shared root array
*Loïc Delmaire*
* Raise an error in generators if an index type is invalid. * Raise an error in generators if an index type is invalid.
*Petrik de Heus* *Petrik de Heus*

View file

@ -247,9 +247,11 @@ module Rails
config, shared = all_configs[env.to_sym], all_configs[:shared] config, shared = all_configs[env.to_sym], all_configs[:shared]
if shared if shared
config = {} if config.nil? config = {} if config.nil? && shared.is_a?(Hash)
if config.is_a?(Hash) if config.is_a?(Hash) && shared.is_a?(Hash)
config = shared.deep_merge(config) config = shared.deep_merge(config)
elsif config.nil?
config = shared
end end
end end

View file

@ -2057,6 +2057,32 @@ module ApplicationTests
assert_equal %w( foo bar ), Rails.application.config.my_custom_config assert_equal %w( foo bar ), Rails.application.config.my_custom_config
end end
test "config_for works with only a shared root array" do
set_custom_config <<~RUBY
shared:
- foo
- bar
RUBY
app "development"
assert_equal %w( foo bar ), Rails.application.config.my_custom_config
end
test "config_for returns only the env array when shared is an array" do
set_custom_config <<~RUBY
development:
- baz
shared:
- foo
- bar
RUBY
app "development"
assert_equal %w( baz ), Rails.application.config.my_custom_config
end
test "config_for uses the Pathname object if it is provided" do test "config_for uses the Pathname object if it is provided" do
set_custom_config <<~RUBY, "Pathname.new(Rails.root.join('config/custom.yml'))" set_custom_config <<~RUBY, "Pathname.new(Rails.root.join('config/custom.yml'))"
development: development: