diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-09 10:14:25 -0800 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-01-09 10:14:25 -0800 |
commit | a67f25d50b5dd9585bb10ecd19bee6a34d69de6a (patch) | |
tree | 7905eb28c88cd6eb900c59beb23c12166bf868dd /activesupport/test | |
parent | 4c32b729517a9a94e3d2a43f76df864fc5fc6e77 (diff) | |
parent | 51215937874dd5e8705701c772b41a7ce522f67c (diff) | |
download | rails-a67f25d50b5dd9585bb10ecd19bee6a34d69de6a.tar.gz rails-a67f25d50b5dd9585bb10ecd19bee6a34d69de6a.tar.bz2 rails-a67f25d50b5dd9585bb10ecd19bee6a34d69de6a.zip |
Merge pull request #13632 from tinogomes/master
Adding Hash#compact and Hash#compact! methods
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 1ee9fbf46e..40c8f03374 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -54,6 +54,8 @@ class HashExtTest < ActiveSupport::TestCase assert_respond_to h, :deep_stringify_keys! assert_respond_to h, :to_options assert_respond_to h, :to_options! + assert_respond_to h, :compact + assert_respond_to h, :compact! end def test_transform_keys @@ -865,6 +867,32 @@ class HashExtTest < ActiveSupport::TestCase original.expects(:delete).never original.except(:a) end + + def test_compact + hash_contain_nil_value = @symbols.merge(z: nil) + hash_with_only_nil_values = { a: nil, b: nil } + + h = hash_contain_nil_value.dup + assert_equal(@symbols, h.compact) + assert_equal(hash_contain_nil_value, h) + + h = hash_with_only_nil_values.dup + assert_equal({}, h.compact) + assert_equal(hash_with_only_nil_values, h) + end + + def test_compact! + hash_contain_nil_value = @symbols.merge(z: nil) + hash_with_only_nil_values = { a: nil, b: nil } + + h = hash_contain_nil_value.dup + assert_equal(@symbols, h.compact!) + assert_equal(@symbols, h) + + h = hash_with_only_nil_values.dup + assert_equal({}, h.compact!) + assert_equal({}, h) + end end class IWriteMyOwnXML |