aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/hash_ext_test.rb
diff options
context:
space:
mode:
authorCorey Ward <corey.atx@gmail.com>2013-11-02 17:03:43 -0500
committerCorey Ward <corey.atx@gmail.com>2013-12-09 13:50:18 -0600
commit0438134476b05d14dffbb28f84eac582bd3cfa8f (patch)
tree97d3f91cff3fe7f3e351d3e1b2305f42f932f5bd /activesupport/test/core_ext/hash_ext_test.rb
parent4aae538d9ffff3a00a81f3da52fa70f7fd79ac74 (diff)
downloadrails-0438134476b05d14dffbb28f84eac582bd3cfa8f.tar.gz
rails-0438134476b05d14dffbb28f84eac582bd3cfa8f.tar.bz2
rails-0438134476b05d14dffbb28f84eac582bd3cfa8f.zip
Fix Hash#deep_merge bug and improve documentation — resolves #12738
Previously merging into a hash with a falsy value would not result in the merge-block being called. The fix is simply to check for presence of the key in the hash. The documentation example for `deep_merge` now appropriately demonstrates what a deep merge does.
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb10
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 1ee9fbf46e..0cbd119654 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -661,6 +661,16 @@ class HashExtTest < ActiveSupport::TestCase
assert_equal expected, hash_1
end
+ def test_deep_merge_with_falsey_values
+ hash_1 = { e: false }
+ hash_2 = { e: 'e' }
+ expected = { e: [:e, false, 'e'] }
+ assert_equal(expected, hash_1.deep_merge(hash_2) { |k,o,n| [k, o, n] })
+
+ hash_1.deep_merge!(hash_2) { |k,o,n| [k, o, n] }
+ assert_equal expected, hash_1
+ end
+
def test_deep_merge_on_indifferent_access
hash_1 = HashWithIndifferentAccess.new({ :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } })
hash_2 = HashWithIndifferentAccess.new({ :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } })