File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -165,6 +165,12 @@ def inherited(base)
165
165
end
166
166
end
167
167
168
+ # Clean the +Errors+ object if instance is duped
169
+ def initialize_dup ( other ) # :nodoc:
170
+ @errors = nil
171
+ super
172
+ end
173
+
168
174
# Returns the +Errors+ object that holds all information about attribute error messages.
169
175
def errors
170
176
@errors ||= Errors . new ( self )
Original file line number Diff line number Diff line change @@ -339,4 +339,19 @@ def test_strict_validation_error_message
339
339
end
340
340
assert_equal "Title can't be blank" , exception . message
341
341
end
342
+
343
+ def test_dup_validity_is_independent
344
+ Topic . validates_presence_of :title
345
+ topic = Topic . new ( "title" => "Litterature" )
346
+ topic . valid?
347
+
348
+ duped = topic . dup
349
+ duped . title = nil
350
+ assert duped . invalid?
351
+
352
+ topic . title = nil
353
+ duped . title = 'Mathematics'
354
+ assert topic . invalid?
355
+ assert duped . valid?
356
+ end
342
357
end
You can’t perform that action at this time.
0 commit comments