Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

clean the errors if an object that includes validations errors is dup…

…ed,for 3-2-stable

It Fixes #5953 in 3-2-stable, it's the same pull request of #6284
  • Loading branch information...
commit 396e383286ccc368b54e980e06a506d339843594 1 parent 007539d
@acapilleri acapilleri authored
View
6 activemodel/lib/active_model/validations.rb
@@ -165,6 +165,12 @@ def inherited(base)
end
end
+ # Clean the +Errors+ object if instance is duped
+ def initialize_dup(other) # :nodoc:
+ @errors = nil
+ super
+ end
+
# Returns the +Errors+ object that holds all information about attribute error messages.
def errors
@errors ||= Errors.new(self)
View
15 activemodel/test/cases/validations_test.rb
@@ -339,4 +339,19 @@ def test_strict_validation_error_message
end
assert_equal "Title can't be blank", exception.message
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
Please sign in to comment.
Something went wrong with that request. Please try again.