Skip to content

Commit d305be0

Browse files
authored
Merge pull request rails#42707 from skelz0r/bugfix/42698
config_for accepts root shared as an array
2 parents e7eac0a + 056b70e commit d305be0

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

railties/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Fix `config_for` error when there's only a shared root array
2+
3+
*Loïc Delmaire*
4+
15
* Raise an error in generators if an index type is invalid.
26

37
*Petrik de Heus*

railties/lib/rails/application.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ def config_for(name, env: Rails.env)
247247
config, shared = all_configs[env.to_sym], all_configs[:shared]
248248

249249
if shared
250-
config = {} if config.nil?
251-
if config.is_a?(Hash)
250+
config = {} if config.nil? && shared.is_a?(Hash)
251+
if config.is_a?(Hash) && shared.is_a?(Hash)
252252
config = shared.deep_merge(config)
253+
elsif config.nil?
254+
config = shared
253255
end
254256
end
255257

railties/test/application/configuration_test.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,32 @@ class D < C
20572057
assert_equal %w( foo bar ), Rails.application.config.my_custom_config
20582058
end
20592059

2060+
test "config_for works with only a shared root array" do
2061+
set_custom_config <<~RUBY
2062+
shared:
2063+
- foo
2064+
- bar
2065+
RUBY
2066+
2067+
app "development"
2068+
2069+
assert_equal %w( foo bar ), Rails.application.config.my_custom_config
2070+
end
2071+
2072+
test "config_for returns only the env array when shared is an array" do
2073+
set_custom_config <<~RUBY
2074+
development:
2075+
- baz
2076+
shared:
2077+
- foo
2078+
- bar
2079+
RUBY
2080+
2081+
app "development"
2082+
2083+
assert_equal %w( baz ), Rails.application.config.my_custom_config
2084+
end
2085+
20602086
test "config_for uses the Pathname object if it is provided" do
20612087
set_custom_config <<~RUBY, "Pathname.new(Rails.root.join('config/custom.yml'))"
20622088
development:

0 commit comments

Comments
 (0)