Skip to content
Browse files

Call super to nullify the reference to the original errors object in …

…the dup'ed object (call ActiveModel::Validations#initialize_dup). Closes #7291
  • Loading branch information...
1 parent da1aa75 commit fb665217723f7c4e9e96bb7658fc3048a1d64379 @csmuc csmuc committed Aug 16, 2012
Showing with 20 additions and 0 deletions.
  1. +5 −0 activerecord/CHANGELOG.md
  2. +1 −0 activerecord/lib/active_record/timestamp.rb
  3. +14 −0 activerecord/test/cases/dup_test.rb
View
5 activerecord/CHANGELOG.md
@@ -269,6 +269,11 @@
*Ari Pollak*
+* 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*
+
* Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
*Roman Shatsov*
View
1 activerecord/lib/active_record/timestamp.rb
@@ -42,6 +42,7 @@ module Timestamp
def initialize_dup(other) # :nodoc:
clear_timestamp_attributes
+ super
end
private
View
14 activerecord/test/cases/dup_test.rb
@@ -107,5 +107,19 @@ def test_dup_after_initialize_callbacks
assert Topic.after_initialize_called
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

0 comments on commit fb66521

Please sign in to comment.
Something went wrong with that request. Please try again.