diff options
author | tinogomes <tinorj@gmail.com> | 2014-01-08 15:46:42 -0200 |
---|---|---|
committer | tinogomes <tinorj@gmail.com> | 2014-01-09 16:02:55 -0200 |
commit | 51215937874dd5e8705701c772b41a7ce522f67c (patch) | |
tree | 840450f8e54d8c98e4ef2db8c7d176674a547330 /activesupport/test/core_ext/hash_ext_test.rb | |
parent | f4fc9e65ed4d51c50ff117ea337206a11b463eeb (diff) | |
download | rails-51215937874dd5e8705701c772b41a7ce522f67c.tar.gz rails-51215937874dd5e8705701c772b41a7ce522f67c.tar.bz2 rails-51215937874dd5e8705701c772b41a7ce522f67c.zip |
Adding Hash#compact and Hash#compact! methods
* Adding Hash#compact and Hash#compact! methods
* Using Ruby 1.9 syntax on documentation
* Updating guides for `Hash#compact` and `Hash#compact!` methods
* Updating CHANGELOG for ActiveSupport
* Removing unecessary protected method and lambda for `Hash#compact` implementations
* Performing `Hash#compact` implementation - https://gist.github.com/tinogomes/8332883
* fixing order position
* Fixing typo
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-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 |