clean the erros if an object that includes validations errors is duped. Fixes #5953
This commit is contained in:
parent
98355fe100
commit
f9ae1baa0a
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user