aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2019-02-13 13:00:47 +0100
committerEdouard CHIN <edouard.chin@shopify.com>2019-02-14 14:11:05 +0100
commit4f7231da7017a198e5cff4735ffee6c7e5bb36a6 (patch)
treedf70894c85f813b8948f5d9d17dc1f4c8fae910c /railties/test
parent8d9d46fdae4502b8881eca641c51a64ee7804194 (diff)
downloadrails-4f7231da7017a198e5cff4735ffee6c7e5bb36a6.tar.gz
rails-4f7231da7017a198e5cff4735ffee6c7e5bb36a6.tar.bz2
rails-4f7231da7017a198e5cff4735ffee6c7e5bb36a6.zip
Fix the `config_for` to always return a NonSymbolAccessDeprecatedHash:
- If you have hashes inside array, the hashes were getting initialized as regular HWIA wereas we want them to be NonSymbolAccessDeprecatedHash in order to trigger a deprecation warning when keys are accessed with string. This patch fixes that by overwriting the `[]=` to to the same as what HWIA does (with the difference that we don't call `convert_key` to not trigger a deprecation when setting value). I also took the liberty to extract `hash.nested_under_indifferent_access`, into a separate method to allow subclasses to return whatever they want. Inheriting HWIA is not common, but I think it's useful for cases like this one where we want to preprocess reading and writing values in the hash (for deprecation purposes or other reasons).
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/application/configuration_test.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/railties/test/application/configuration_test.rb b/railties/test/application/configuration_test.rb
index 960f708bdf..f3161ad2a8 100644
--- a/railties/test/application/configuration_test.rb
+++ b/railties/test/application/configuration_test.rb
@@ -1787,6 +1787,28 @@ module ApplicationTests
end
end
+ test "config_for loads nested custom configuration inside array from yaml with deprecated non-symbol access" do
+ app_file "config/custom.yml", <<-RUBY
+ development:
+ foo:
+ bar:
+ - baz: 1
+ RUBY
+
+ add_to_config <<-RUBY
+ config.my_custom_config = config_for('custom')
+ RUBY
+
+ app "development"
+
+ config = Rails.application.config.my_custom_config
+ assert_instance_of Rails::Application::NonSymbolAccessDeprecatedHash, config[:foo][:bar].first
+
+ assert_deprecated do
+ assert_equal 1, config[:foo][:bar].first["baz"]
+ end
+ end
+
test "config_for makes all hash methods available" do
app_file "config/custom.yml", <<-RUBY
development: