aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-03-28 21:17:38 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-03-28 21:17:38 +0000
commitad8df03f9c831d88b8a7eb80c1b7dbcf02fc1b19 (patch)
treee38fac0f66c06e576e0127a9553fed5f26c297ed /activeresource/test
parent5c0656c9ee9ecc7ffeebea69dc0cd371d978b254 (diff)
downloadrails-ad8df03f9c831d88b8a7eb80c1b7dbcf02fc1b19.tar.gz
rails-ad8df03f9c831d88b8a7eb80c1b7dbcf02fc1b19.tar.bz2
rails-ad8df03f9c831d88b8a7eb80c1b7dbcf02fc1b19.zip
Add #clone. Closes #7352 [Ryan Daigle, thechrisoshow]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9121 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activeresource/test')
-rw-r--r--activeresource/test/base_test.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/activeresource/test/base_test.rb b/activeresource/test/base_test.rb
index 13709f1ca1..9caca803b7 100644
--- a/activeresource/test/base_test.rb
+++ b/activeresource/test/base_test.rb
@@ -558,6 +558,41 @@ class BaseTest < Test::Unit::TestCase
assert_raises(ActiveResource::ResourceConflict) { Person.create(:name => 'Rick') }
end
+ def test_clone
+ matz = Person.find(1)
+ matz_c = matz.clone
+ assert matz_c.new?
+ matz.attributes.each do |k, v|
+ assert_equal v, matz_c.send(k) if k != Person.primary_key
+ end
+ end
+
+ def test_nested_clone
+ addy = StreetAddress.find(1, :params => {:person_id => 1})
+ addy_c = addy.clone
+ assert addy_c.new?
+ addy.attributes.each do |k, v|
+ assert_equal v, addy_c.send(k) if k != StreetAddress.primary_key
+ end
+ assert_equal addy.prefix_options, addy_c.prefix_options
+ end
+
+ def test_complex_clone
+ matz = Person.find(1)
+ matz.address = StreetAddress.find(1, :params => {:person_id => matz.id})
+ matz.non_ar_hash = {:not => "an ARes instance"}
+ matz.non_ar_arr = ["not", "ARes"]
+ matz_c = matz.clone
+ assert matz_c.new?
+ assert_raises(NoMethodError) {matz_c.address}
+ assert_equal matz.non_ar_hash, matz_c.non_ar_hash
+ assert_equal matz.non_ar_arr, matz_c.non_ar_arr
+
+ # Test that actual copy, not just reference copy
+ matz.non_ar_hash[:not] = "changed"
+ assert_not_equal matz.non_ar_hash, matz_c.non_ar_hash
+ end
+
def test_update
matz = Person.find(:first)
matz.name = "David"