From 47f39d26a76430ad50dae79f212d118849b2af40 Mon Sep 17 00:00:00 2001 From: Franck Verrot Date: Wed, 24 Nov 2010 16:32:02 +0800 Subject: [PATCH] Testing that dup is resetting the timestamps --- activerecord/test/cases/dup_test.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) 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 @@ 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 -- GitLab