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

Ensure Rails.application.config_for always cast hashes to ActiveSupport::OrderedOptions.

Fix: #42037
This commit is contained in:
Jean Boussier 2021-04-21 17:16:38 +02:00
parent 5649be94ff
commit 3fe0ab52df
3 changed files with 39 additions and 6 deletions

View file

@ -1,3 +1,7 @@
* Ensure `Rails.application.config_for` always cast hashes to `ActiveSupport::OrderedOptions`.
*Jean Boussier*
* Remove Rack::Runtime from the default middleware stack and deprecate
referencing it in middleware operations without adding it back

View file

@ -246,11 +246,18 @@ module Rails
all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
config, shared = all_configs[env.to_sym], all_configs[:shared]
if config.is_a?(Hash)
ActiveSupport::OrderedOptions.new.update(shared&.deep_merge(config) || config)
else
config || shared
if shared
config = {} if config.nil?
if config.is_a?(Hash)
config = shared.deep_merge(config)
end
end
if config.is_a?(Hash)
config = ActiveSupport::OrderedOptions.new.update(config)
end
config
else
raise "Could not load configuration. No such file - #{yaml}"
end

View file

@ -2106,10 +2106,10 @@ module ApplicationTests
end
test "config_for containing ERB tags should evaluate" do
set_custom_config <<~RUBY
set_custom_config <<~YAML
development:
key: <%= 'custom key' %>
RUBY
YAML
app "development"
@ -2154,6 +2154,28 @@ module ApplicationTests
end
end
test "config_for returns a ActiveSupport::OrderedOptions" do
app_file "config/custom.yml", <<~YAML
shared:
some_key: default
development:
some_key: value
test:
YAML
app "development"
config = Rails.application.config_for(:custom)
assert_instance_of ActiveSupport::OrderedOptions, config
assert_equal "value", config.some_key
config = Rails.application.config_for(:custom, env: :test)
assert_instance_of ActiveSupport::OrderedOptions, config
assert_equal "default", config.some_key
end
test "api_only is false by default" do
app "development"
assert_not Rails.application.config.api_only