diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2016-12-17 19:15:09 +0900 |
---|---|---|
committer | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2017-01-06 17:49:18 +0900 |
commit | d97ba3447268f6c72ca545221a22714641d98325 (patch) | |
tree | 857c31f6e898ac65c92647272d9bf794d2e8f020 /activesupport/test | |
parent | b1df82e41275e781fee4dd79264c95c3f21fad6d (diff) | |
download | rails-d97ba3447268f6c72ca545221a22714641d98325.tar.gz rails-d97ba3447268f6c72ca545221a22714641d98325.tar.bz2 rails-d97ba3447268f6c72ca545221a22714641d98325.zip |
ensure `#compact` of HWIDA to return HWIDA
`Hash#compact` of Ruby native returns new hash.
Therefore, in order to return HWIDA as in the past version, need to
define own `#compact` to HWIDA.
Related: #26868
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index bea0a84b53..05813ad388 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -589,6 +589,16 @@ class HashExtTest < ActiveSupport::TestCase assert_instance_of ActiveSupport::HashWithIndifferentAccess, indifferent_strings end + def test_indifferent_compact + hash_contain_nil_value = @strings.merge("z" => nil) + hash = ActiveSupport::HashWithIndifferentAccess.new(hash_contain_nil_value) + compacted_hash = hash.compact + + assert_equal(@strings, compacted_hash) + assert_equal(hash_contain_nil_value, hash) + assert_instance_of ActiveSupport::HashWithIndifferentAccess, compacted_hash + end + def test_indifferent_to_hash # Should convert to a Hash with String keys. assert_equal @strings, @mixed.with_indifferent_access.to_hash |