diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-02-20 09:36:40 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-20 09:36:40 +0100 |
commit | 71da39097b67114329be6d8db7fe6911124531af (patch) | |
tree | f2caf42ba1e673f21c498ab15a005cba015cf2fc /activesupport | |
parent | 41c33bd4b2ec3f4a482e6030b6fda15091d81e4a (diff) | |
parent | e532531939a610c3a1ba4594d325b10a0c9b4546 (diff) | |
download | rails-71da39097b67114329be6d8db7fe6911124531af.tar.gz rails-71da39097b67114329be6d8db7fe6911124531af.tar.bz2 rails-71da39097b67114329be6d8db7fe6911124531af.zip |
Merge pull request #27925 from robin850/hwia-removal
Remove the top-level `HashWithIndifferentAccess` contant
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activesupport/lib/active_support/hash_with_indifferent_access.rb | 18 | ||||
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 23 |
3 files changed, 46 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 2fb7f29d73..788ea88752 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,3 +1,9 @@ +* Deprecated the top level `HashWithIndifferentAccess` constant. + + Only `ActiveSupport::HashWithIndifferentAccess` should be used now. + + *Robin Dupret* (#27925) + * Deprecate `.halt_callback_chains_on_return_false`. *Rafael Mendonça França* diff --git a/activesupport/lib/active_support/hash_with_indifferent_access.rb b/activesupport/lib/active_support/hash_with_indifferent_access.rb index 79e7feaf47..8638667082 100644 --- a/activesupport/lib/active_support/hash_with_indifferent_access.rb +++ b/activesupport/lib/active_support/hash_with_indifferent_access.rb @@ -316,4 +316,20 @@ module ActiveSupport end end -HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess +class HashWithIndifferentAccess < ActiveSupport::HashWithIndifferentAccess + def initialize(*) + ActiveSupport::Deprecation.warn "HashWithIndifferentAccess is deprecated!" \ + "Use ActiveSupport::HashWithIndifferentAccess instead." + super + end + + def self.inherited(*) + ActiveSupport::Deprecation.warn "HashWithIndifferentAccess is deprecated!" \ + "Use ActiveSupport::HashWithIndifferentAccess instead." + super + end + + def encode_with(coder) + coder.represent_object(nil, ActiveSupport::HashWithIndifferentAccess.new(self)) + end +end diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 05813ad388..042bb60a22 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -8,6 +8,8 @@ require "active_support/core_ext/object/deep_dup" require "active_support/inflections" class HashExtTest < ActiveSupport::TestCase + HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess + class IndifferentHash < ActiveSupport::HashWithIndifferentAccess end @@ -1078,6 +1080,25 @@ class HashExtTest < ActiveSupport::TestCase assert_equal 1, hash[:a] assert_equal 3, hash[:b] end + + def test_top_level_hash_with_indifferent_access_is_deprecated + assert_deprecated do + ::HashWithIndifferentAccess.new + end + end + + def test_top_level_hash_with_indifferent_access_can_be_extended + assert_deprecated do + Class.new(::HashWithIndifferentAccess) + end + end + + def test_yaml_encoding_outputs_an_activesupport_namespaced_constant + ActiveSupport::Deprecation.silence do + instance = ::HashWithIndifferentAccess.new + assert_includes instance.to_yaml, "ActiveSupport::HashWithIndifferentAccess" + end + end end class IWriteMyOwnXML @@ -1123,6 +1144,8 @@ class HashExtToParamTests < ActiveSupport::TestCase end class HashToXmlTest < ActiveSupport::TestCase + HashWithIndifferentAccess = ActiveSupport::HashWithIndifferentAccess + def setup @xml_options = { root: :person, skip_instruct: true, indent: 0 } end |