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:
parent
5649be94ff
commit
3fe0ab52df
3 changed files with 39 additions and 6 deletions
|
@ -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
|
* Remove Rack::Runtime from the default middleware stack and deprecate
|
||||||
referencing it in middleware operations without adding it back
|
referencing it in middleware operations without adding it back
|
||||||
|
|
||||||
|
|
|
@ -246,11 +246,18 @@ module Rails
|
||||||
all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
|
all_configs = ActiveSupport::ConfigurationFile.parse(yaml).deep_symbolize_keys
|
||||||
config, shared = all_configs[env.to_sym], all_configs[:shared]
|
config, shared = all_configs[env.to_sym], all_configs[:shared]
|
||||||
|
|
||||||
if config.is_a?(Hash)
|
if shared
|
||||||
ActiveSupport::OrderedOptions.new.update(shared&.deep_merge(config) || config)
|
config = {} if config.nil?
|
||||||
else
|
if config.is_a?(Hash)
|
||||||
config || shared
|
config = shared.deep_merge(config)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if config.is_a?(Hash)
|
||||||
|
config = ActiveSupport::OrderedOptions.new.update(config)
|
||||||
|
end
|
||||||
|
|
||||||
|
config
|
||||||
else
|
else
|
||||||
raise "Could not load configuration. No such file - #{yaml}"
|
raise "Could not load configuration. No such file - #{yaml}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -2106,10 +2106,10 @@ module ApplicationTests
|
||||||
end
|
end
|
||||||
|
|
||||||
test "config_for containing ERB tags should evaluate" do
|
test "config_for containing ERB tags should evaluate" do
|
||||||
set_custom_config <<~RUBY
|
set_custom_config <<~YAML
|
||||||
development:
|
development:
|
||||||
key: <%= 'custom key' %>
|
key: <%= 'custom key' %>
|
||||||
RUBY
|
YAML
|
||||||
|
|
||||||
app "development"
|
app "development"
|
||||||
|
|
||||||
|
@ -2154,6 +2154,28 @@ module ApplicationTests
|
||||||
end
|
end
|
||||||
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
|
test "api_only is false by default" do
|
||||||
app "development"
|
app "development"
|
||||||
assert_not Rails.application.config.api_only
|
assert_not Rails.application.config.api_only
|
||||||
|
|
Loading…
Reference in a new issue