aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/dup_test.rb
diff options
context:
space:
mode:
authorFranck Verrot <franck@verrot.fr>2010-11-24 16:32:02 +0800
committerAaron Patterson <aaron.patterson@gmail.com>2010-11-25 01:18:43 +0800
commit47f39d26a76430ad50dae79f212d118849b2af40 (patch)
tree23fa69be9466fe537551dc83ff7a89727203c57b /activerecord/test/cases/dup_test.rb
parent8624065bffd203e1f590ca431d468f9b38e9fb7f (diff)
downloadrails-47f39d26a76430ad50dae79f212d118849b2af40.tar.gz
rails-47f39d26a76430ad50dae79f212d118849b2af40.tar.bz2
rails-47f39d26a76430ad50dae79f212d118849b2af40.zip
Testing that dup is resetting the timestamps
Diffstat (limited to 'activerecord/test/cases/dup_test.rb')
-rw-r--r--activerecord/test/cases/dup_test.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/activerecord/test/cases/dup_test.rb b/activerecord/test/cases/dup_test.rb
index 46abe7792c..0236f9b0a1 100644
--- a/activerecord/test/cases/dup_test.rb
+++ b/activerecord/test/cases/dup_test.rb
@@ -51,7 +51,12 @@ module ActiveRecord
topic.attributes = dbtopic.attributes
+ #duped has no timestamp values
duped = dbtopic.dup
+
+ #clear topic timestamp values
+ topic.send(:clear_timestamp_attributes)
+
assert_equal topic.changes, duped.changes
end
@@ -75,5 +80,24 @@ module ActiveRecord
assert_equal 'Aaron', topic.author_name
assert_equal 'meow', duped.author_name
end
+
+ def test_dup_timestamps_are_cleared
+ topic = Topic.first
+ assert_not_nil topic.updated_at
+ assert_not_nil topic.created_at
+
+ # temporary change to the topic object
+ topic.updated_at -= 3.days
+
+ #dup should not preserve the timestamps if present
+ new_topic = topic.dup
+ assert_nil new_topic.updated_at
+ assert_nil new_topic.created_at
+
+ new_topic.save
+ assert_not_nil new_topic.updated_at
+ assert_not_nil new_topic.created_at
+ end
+
end
end