mirror of
https://github.com/github/rails.git
synced 2026-01-09 14:48:01 -05:00
Merge pull request #7371 from csmuc/fix_dup_validation_errors
Dup'ed ActiveRecord objects may not share the errors object Conflicts: activerecord/CHANGELOG.md activerecord/test/cases/dup_test.rb
This commit is contained in:
committed by
Rafael Mendonça França
parent
d92e66f14c
commit
9a38e73c63
@@ -1,5 +1,10 @@
|
||||
## Rails 3.2.9 (unreleased)
|
||||
|
||||
* 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*
|
||||
|
||||
* Synchronize around deleting from the reserved connections hash.
|
||||
Fixes #7955
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ module ActiveRecord
|
||||
|
||||
def initialize_dup(other)
|
||||
clear_timestamp_attributes
|
||||
super
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -98,5 +98,20 @@ module ActiveRecord
|
||||
assert_not_nil new_topic.updated_at
|
||||
assert_not_nil new_topic.created_at
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user