diff options
author | Lawrence Pit <lawrence.pit@gmail.com> | 2008-07-14 11:53:41 +1000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-17 01:59:08 +0100 |
commit | 40dbebba28bfa1c55737da7354542c3bdca4e1a1 (patch) | |
tree | f21c9a31379dae25b5cedae5ea00053a272d9408 /activesupport/test/core_ext | |
parent | cd6301557005617583e3f9ca5fb56297adcce7cc (diff) | |
download | rails-40dbebba28bfa1c55737da7354542c3bdca4e1a1.tar.gz rails-40dbebba28bfa1c55737da7354542c3bdca4e1a1.tar.bz2 rails-40dbebba28bfa1c55737da7354542c3bdca4e1a1.zip |
Allow deep merging of hash values for nested with_options. [#490 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 10 |
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 26e65075eb..5d2053f106 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -245,6 +245,16 @@ class HashExtTest < Test::Unit::TestCase assert(!indiff.keys.any? {|k| k.kind_of? String}, "A key was converted to a string!") end + def test_deep_merge + hash_1 = { :a => "a", :b => "b", :c => { :c1 => "c1", :c2 => "c2", :c3 => { :d1 => "d1" } } } + hash_2 = { :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) + + 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 } |