Permalink
Browse files

Testing that dup is resetting the timestamps

  • Loading branch information...
1 parent 8624065 commit 47f39d26a76430ad50dae79f212d118849b2af40 @franckverrot franckverrot committed with tenderlove Nov 24, 2010
Showing with 24 additions and 0 deletions.
  1. +24 −0 activerecord/test/cases/dup_test.rb
@@ -51,7 +51,12 @@ def test_dup_with_changes
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 @@ def test_dup_attributes_are_independent
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

0 comments on commit 47f39d2

Please sign in to comment.