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:
parent
398561bfbb
commit
056b70ee4f
3 changed files with 34 additions and 2 deletions
|
@ -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.
|
||||
|
||||
*Petrik de Heus*
|
||||
|
|
|
@ -247,9 +247,11 @@ module Rails
|
|||
config, shared = all_configs[env.to_sym], all_configs[:shared]
|
||||
|
||||
if shared
|
||||
config = {} if config.nil?
|
||||
if config.is_a?(Hash)
|
||||
config = {} if config.nil? && shared.is_a?(Hash)
|
||||
if config.is_a?(Hash) && shared.is_a?(Hash)
|
||||
config = shared.deep_merge(config)
|
||||
elsif config.nil?
|
||||
config = shared
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2057,6 +2057,32 @@ module ApplicationTests
|
|||
assert_equal %w( foo bar ), Rails.application.config.my_custom_config
|
||||
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
|
||||
set_custom_config <<~RUBY, "Pathname.new(Rails.root.join('config/custom.yml'))"
|
||||
development:
|
||||
|
|
Loading…
Reference in a new issue