aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/object/deep_dup_test.rb
diff options
context:
space:
mode:
authorAkshay Vishnoi <akshay.vishnoi@vinsol.com>2014-04-13 12:32:00 +0530
committerAkshay Vishnoi <akshay.vishnoi@vinsol.com>2014-04-13 12:32:00 +0530
commitd815ca26f5ee94256f36a37bda6e86be37a118a3 (patch)
tree6494c78248c3e7bb6dbf75df67a8bd2352cd6577 /activesupport/test/core_ext/object/deep_dup_test.rb
parent47d9321a1ee88368cc24de7cad5f42a28066d1a0 (diff)
downloadrails-d815ca26f5ee94256f36a37bda6e86be37a118a3.tar.gz
rails-d815ca26f5ee94256f36a37bda6e86be37a118a3.tar.bz2
rails-d815ca26f5ee94256f36a37bda6e86be37a118a3.zip
Move tests for deep_dup and duplicable to object directory
Diffstat (limited to 'activesupport/test/core_ext/object/deep_dup_test.rb')
-rw-r--r--activesupport/test/core_ext/object/deep_dup_test.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/object/deep_dup_test.rb b/activesupport/test/core_ext/object/deep_dup_test.rb
new file mode 100644
index 0000000000..91d558dbb5
--- /dev/null
+++ b/activesupport/test/core_ext/object/deep_dup_test.rb
@@ -0,0 +1,53 @@
+require 'abstract_unit'
+require 'active_support/core_ext/object'
+
+class DeepDupTest < ActiveSupport::TestCase
+
+ def test_array_deep_dup
+ array = [1, [2, 3]]
+ dup = array.deep_dup
+ dup[1][2] = 4
+ assert_equal nil, array[1][2]
+ assert_equal 4, dup[1][2]
+ end
+
+ def test_hash_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_array_deep_dup_with_hash_inside
+ array = [1, { :a => 2, :b => 3 } ]
+ dup = array.deep_dup
+ dup[1][:c] = 4
+ assert_equal nil, array[1][:c]
+ assert_equal 4, dup[1][:c]
+ end
+
+ def test_hash_deep_dup_with_array_inside
+ hash = { :a => [1, 2] }
+ dup = hash.deep_dup
+ dup[:a][2] = 'c'
+ assert_equal nil, hash[:a][2]
+ assert_equal 'c', dup[:a][2]
+ 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_object_deep_dup
+ object = Object.new
+ dup = object.deep_dup
+ dup.instance_variable_set(:@a, 1)
+ assert !object.instance_variable_defined?(:@a)
+ assert dup.instance_variable_defined?(:@a)
+ end
+
+end