Skip to content

Commit

Permalink
Merge pull request #7371 from csmuc/fix_dup_validation_errors
Browse files Browse the repository at this point in the history
Dup'ed ActiveRecord objects may not share the errors object
  • Loading branch information
spastorino committed Oct 16, 2012
2 parents 12a0383 + fb66521 commit c432c74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions activerecord/CHANGELOG.md
Expand Up @@ -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*
Expand Down
1 change: 1 addition & 0 deletions activerecord/lib/active_record/timestamp.rb
Expand Up @@ -42,6 +42,7 @@ module Timestamp

def initialize_dup(other) # :nodoc:
clear_timestamp_attributes
super
end

private
Expand Down
14 changes: 14 additions & 0 deletions activerecord/test/cases/dup_test.rb
Expand Up @@ -107,5 +107,19 @@ def test_dup_after_initialize_callbacks
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

0 comments on commit c432c74

Please sign in to comment.