Skip to content
This repository
Browse code

Call super to nullify the reference to the original errors object in …

…the dup'ed object (call ActiveModel::Validations#initialize_dup). Closes #7291
  • Loading branch information...
commit fb665217723f7c4e9e96bb7658fc3048a1d64379 1 parent da1aa75
Christian Seiler csmuc authored
5 activerecord/CHANGELOG.md
Source Rendered
@@ -269,6 +269,11 @@
269 269
270 270 *Ari Pollak*
271 271
  272 +* Fix AR#dup to nullify the validation errors in the dup'ed object. Previously the original
  273 + and the dup'ed object shared the same errors.
  274 +
  275 + * Christian Seiler*
  276 +
272 277 * Raise `ArgumentError` if list of attributes to change is empty in `update_all`.
273 278
274 279 *Roman Shatsov*
1  activerecord/lib/active_record/timestamp.rb
@@ -42,6 +42,7 @@ module Timestamp
42 42
43 43 def initialize_dup(other) # :nodoc:
44 44 clear_timestamp_attributes
  45 + super
45 46 end
46 47
47 48 private
14 activerecord/test/cases/dup_test.rb
@@ -107,5 +107,19 @@ def test_dup_after_initialize_callbacks
107 107 assert Topic.after_initialize_called
108 108 end
109 109
  110 + def test_dup_validity_is_independent
  111 + Topic.validates_presence_of :title
  112 + topic = Topic.new("title" => "Litterature")
  113 + topic.valid?
  114 +
  115 + duped = topic.dup
  116 + duped.title = nil
  117 + assert duped.invalid?
  118 +
  119 + topic.title = nil
  120 + duped.title = 'Mathematics'
  121 + assert topic.invalid?
  122 + assert duped.valid?
  123 + end
110 124 end
111 125 end

0 comments on commit fb66521

Please sign in to comment.
Something went wrong with that request. Please try again.