aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-10-16 09:46:44 -0700
committerSantiago Pastorino <santiago@wyeworks.com>2012-10-16 09:46:44 -0700
commitc432c74cd34d4230bfda6fa008f2af9dbc33e523 (patch)
tree85bb3bc77c1b016f67f488425ca1c2419bde2905
parent12a038390863e45ea99afaec2a54451167720971 (diff)
parentfb665217723f7c4e9e96bb7658fc3048a1d64379 (diff)
downloadrails-c432c74cd34d4230bfda6fa008f2af9dbc33e523.tar.gz
rails-c432c74cd34d4230bfda6fa008f2af9dbc33e523.tar.bz2
rails-c432c74cd34d4230bfda6fa008f2af9dbc33e523.zip
Merge pull request #7371 from csmuc/fix_dup_validation_errors
Dup'ed ActiveRecord objects may not share the errors object
-rw-r--r--activerecord/CHANGELOG.md5
-rw-r--r--activerecord/lib/active_record/timestamp.rb1
-rw-r--r--activerecord/test/cases/dup_test.rb14
3 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md
index dd029540cf..5f5c9e4915 100644
--- a/activerecord/CHANGELOG.md
+++ b/activerecord/CHANGELOG.md
@@ -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*
diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb
index bf95ccb298..dd08a6f4f5 100644
--- a/activerecord/lib/active_record/timestamp.rb
+++ b/activerecord/lib/active_record/timestamp.rb
@@ -42,6 +42,7 @@ module ActiveRecord
def initialize_dup(other) # :nodoc:
clear_timestamp_attributes
+ super
end
private
diff --git a/activerecord/test/cases/dup_test.rb b/activerecord/test/cases/dup_test.rb
index 71b2b16608..4e2adff344 100644
--- a/activerecord/test/cases/dup_test.rb
+++ b/activerecord/test/cases/dup_test.rb
@@ -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