diff options
author | Robin Dupret <robin.dupret@gmail.com> | 2017-02-24 23:34:59 +0100 |
---|---|---|
committer | Robin Dupret <robin.dupret@gmail.com> | 2017-02-25 00:38:41 +0100 |
commit | ac57a3ee0e9d484f3d665f42933fcda864546349 (patch) | |
tree | 27f73d04cee9dff5a61800d0d22cad47acefa2c7 /activesupport/test | |
parent | e690a92b4498f2b65998656c625919767854623d (diff) | |
download | rails-ac57a3ee0e9d484f3d665f42933fcda864546349.tar.gz rails-ac57a3ee0e9d484f3d665f42933fcda864546349.tar.bz2 rails-ac57a3ee0e9d484f3d665f42933fcda864546349.zip |
Add few tests for the top level `HashWithIndifferentAccess`
This ensures that if we try to hard-deprecate it again in the future,
we won't break these behaviors.
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index efe211677e..525ea08abd 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -1090,6 +1090,30 @@ class HashExtTest < ActiveSupport::TestCase assert_equal 1, hash[:a] assert_equal 3, hash[:b] end + + def test_inheriting_from_top_level_hash_with_indifferent_access_preserves_ancestors_chain + klass = Class.new(::HashWithIndifferentAccess) + assert_equal ActiveSupport::HashWithIndifferentAccess, klass.ancestors[1] + end + + def test_inheriting_from_hash_with_indifferent_access_properly_dumps_ivars + klass = Class.new(::HashWithIndifferentAccess) do + def initialize(*) + @foo = "bar" + super + end + end + + yaml_output = klass.new.to_yaml + + # `hash-with-ivars` was introduced in 2.0.9 (https://git.io/vyUQW) + if Gem::Version.new(Psych::VERSION) >= Gem::Version.new("2.0.9") + assert_includes yaml_output, "hash-with-ivars" + assert_includes yaml_output, "@foo: bar" + else + assert_includes yaml_output, "hash" + end + end end class IWriteMyOwnXML |