diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 5 | ||||
-rw-r--r-- | activerecord/lib/active_record/timestamp.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/dup_test.rb | 15 |
3 files changed, 21 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 75f9d76730..aafdbec25c 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,10 @@ ## Rails 3.2.9 (unreleased) +* Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original + and the dup'ed object shared the same errors. + + * Christian Seiler* + * Synchronize around deleting from the reserved connections hash. Fixes #7955 diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index 0c760e9850..ab25dc52f9 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -39,6 +39,7 @@ module ActiveRecord def initialize_dup(other) clear_timestamp_attributes + super end private diff --git a/activerecord/test/cases/dup_test.rb b/activerecord/test/cases/dup_test.rb index 303f616c61..b2a3cb5733 100644 --- a/activerecord/test/cases/dup_test.rb +++ b/activerecord/test/cases/dup_test.rb @@ -98,5 +98,20 @@ module ActiveRecord assert_not_nil new_topic.updated_at assert_not_nil new_topic.created_at end + + def test_dup_validity_is_independent + Topic.validates_presence_of :title + topic = Topic.new("title" => "Litterature") + topic.valid? + + duped = topic.dup + duped.title = nil + assert duped.invalid? + + topic.title = nil + duped.title = 'Mathematics' + assert topic.invalid? + assert duped.valid? + end end end |