diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-10-28 19:43:21 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-11-02 17:14:52 +0100 |
commit | 5071b727b438f1ca6be502c906f5af751abb0229 (patch) | |
tree | fba52afb44767c7d594a48c446bcbac8daff5886 /activesupport/test | |
parent | cfbe5958311f21397c98657c3370d03dcf720fe1 (diff) | |
download | rails-5071b727b438f1ca6be502c906f5af751abb0229.tar.gz rails-5071b727b438f1ca6be502c906f5af751abb0229.tar.bz2 rails-5071b727b438f1ca6be502c906f5af751abb0229.zip |
Added Hash#deep_dup function which performs deep duplication on given hash
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/core_ext/hash_ext_test.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 545fed2684..bfcfddad47 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -316,6 +316,21 @@ class HashExtTest < Test::Unit::TestCase assert_equal expected, hash_1 end + def test_deep_dup + hash = { :a => { :b => 'b' } } + dup = hash.deep_dup + dup[:a][:c] = 'c' + assert_equal nil, hash[:a][:c] + assert_equal 'c', dup[:a][:c] + end + + def test_deep_dup_initialize + zero_hash = Hash.new 0 + hash = { :a => zero_hash } + dup = hash.deep_dup + assert_equal 0, dup[:a][44] + end + def test_store_on_indifferent_access hash = HashWithIndifferentAccess.new hash.store(:test1, 1) |