mirror of
https://github.com/github/rails.git
synced 2026-01-10 07:07:54 -05:00
clean the errors if an object that includes validations errors is duped,for 3-2-stable
It Fixes #5953 in 3-2-stable, it's the same pull request of #6284
This commit is contained in:
@@ -165,6 +165,12 @@ module ActiveModel
|
||||
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)
|
||||
|
||||
@@ -339,4 +339,19 @@ class ValidationsTest < ActiveModel::TestCase
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user