diff options
author | Andrew Moreland <andy@andymo.org> | 2009-08-09 15:38:30 -0700 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-08-09 17:32:04 -0700 |
commit | ca92d44e7637ae6d28d6b88b67873d2795290cb5 (patch) | |
tree | b7237174a7289ba34b6bbf9569521c6786d52f4e /activesupport/test/core_ext | |
parent | 0af4b0755f507d41590b5315966c9a20949f79f9 (diff) | |
download | rails-ca92d44e7637ae6d28d6b88b67873d2795290cb5.tar.gz rails-ca92d44e7637ae6d28d6b88b67873d2795290cb5.tar.bz2 rails-ca92d44e7637ae6d28d6b88b67873d2795290cb5.zip |
Support deep-merging HashWithIndifferentAccess.
[#2732 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 8b0f3fc33c..eb4c37aaf0 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -265,6 +265,18 @@ class HashExtTest < Test::Unit::TestCase 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" } } }) + hash_3 = { :a => 1, :c => { :c1 => 2, :c3 => { :d2 => "d2" } } } + expected = { "a" => 1, "b" => "b", "c" => { "c1" => 2, "c2" => "c2", "c3" => { "d1" => "d1", "d2" => "d2" } } } + assert_equal expected, hash_1.deep_merge(hash_2) + assert_equal expected, hash_1.deep_merge(hash_3) + + hash_1.deep_merge!(hash_2) + assert_equal expected, hash_1 + end + def test_reverse_merge defaults = { :a => "x", :b => "y", :c => 10 }.freeze options = { :a => 1, :b => 2 } |