Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6284 from acapilleri/dup_validation

clean the erros if an object that includes validation  is duped.
  • Loading branch information...
commit 3d1b078a5b23d03fa827779767a0f97aa3ccac4b 2 parents dd42e89 + f9ae1ba
@carlosantoniodasilva carlosantoniodasilva authored
View
6 activemodel/lib/active_model/validations.rb
@@ -177,6 +177,12 @@ def inherited(base)
super
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
View
15 activemodel/test/cases/validations_test.rb
@@ -344,4 +344,19 @@ def test_does_not_modify_options_argument
Topic.validates :title, options
assert_equal({ :presence => true }, options)
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.