aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/hash_ext_test.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-07 17:59:19 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-05-07 18:03:03 -0300
commit6b2f37741cf4f55c6237f0d8cde45c9caea4cf12 (patch)
tree4a25c448a2f5a2937ca70dd6d4f644844d996886 /activesupport/test/core_ext/hash_ext_test.rb
parent73fb39b6faa9de593ae75ad4e3b8e065ea0e53af (diff)
parent0438134476b05d14dffbb28f84eac582bd3cfa8f (diff)
downloadrails-6b2f37741cf4f55c6237f0d8cde45c9caea4cf12.tar.gz
rails-6b2f37741cf4f55c6237f0d8cde45c9caea4cf12.tar.bz2
rails-6b2f37741cf4f55c6237f0d8cde45c9caea4cf12.zip
Merge pull request #12746 from coreyward/master
Fix Hash#deep_merge bug and improve documentation — resolves #12738
Diffstat (limited to 'activesupport/test/core_ext/hash_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/hash_ext_test.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb
index d824a16e98..ad354a4c30 100644
--- a/activesupport/test/core_ext/hash_ext_test.rb
+++ b/activesupport/test/core_ext/hash_ext_test.rb
@@ -697,6 +697,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" } } })
@@ -905,11 +915,11 @@ class HashExtTest < ActiveSupport::TestCase
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)
@@ -918,11 +928,11 @@ class HashExtTest < ActiveSupport::TestCase
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)