aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2007-10-08 06:21:38 +0000
committerMichael Koziarski <michael@koziarski.com>2007-10-08 06:21:38 +0000
commit3122d321fd5d05d549274487e5a52f3a73bc6f43 (patch)
tree11d92375dd5ac760b3ef75148836794f30ab2592 /activerecord/test
parent4eaa8ba5bec9001e97349e7dfd565c7215085834 (diff)
downloadrails-3122d321fd5d05d549274487e5a52f3a73bc6f43.tar.gz
rails-3122d321fd5d05d549274487e5a52f3a73bc6f43.tar.bz2
rails-3122d321fd5d05d549274487e5a52f3a73bc6f43.zip
Make sure AR::Base#clone handles attr changes made in after_initialize hooks. Closes #7191 [weyus]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7802 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/base_test.rb4
-rwxr-xr-xactiverecord/test/fixtures/topic.rb8
2 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb
index 650d87f91f..5e20cbe127 100755
--- a/activerecord/test/base_test.rb
+++ b/activerecord/test/base_test.rb
@@ -1008,6 +1008,10 @@ class BasicsTest < Test::Unit::TestCase
cloned_topic.title["a"] = "c"
assert_equal "b", topic.title["a"]
+ #test if attributes set as part of after_initialize are cloned correctly
+ assert_equal topic.author_email_address, cloned_topic.author_email_address
+
+ # test if saved clone object differs from original
cloned_topic.save
assert !cloned_topic.new_record?
assert cloned_topic.id != topic.id
diff --git a/activerecord/test/fixtures/topic.rb b/activerecord/test/fixtures/topic.rb
index dd71d6bf2b..b2541c8640 100755
--- a/activerecord/test/fixtures/topic.rb
+++ b/activerecord/test/fixtures/topic.rb
@@ -28,4 +28,10 @@ class Topic < ActiveRecord::Base
def destroy_children
self.class.delete_all "parent_id = #{id}"
end
-end
+
+ def after_initialize
+ if self.new_record?
+ self.author_email_address = 'test@test.com'
+ end
+ end
+end \ No newline at end of file