mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #7371 from csmuc/fix_dup_validation_errors
Dup'ed ActiveRecord objects may not share the errors object
This commit is contained in:
commit
c432c74cd3
3 changed files with 20 additions and 0 deletions
|
@ -288,6 +288,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*
|
||||
|
|
|
@ -42,6 +42,7 @@ module ActiveRecord
|
|||
|
||||
def initialize_dup(other) # :nodoc:
|
||||
clear_timestamp_attributes
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -107,5 +107,19 @@ module ActiveRecord
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue