File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -492,6 +492,7 @@ def becomes(klass)
492
492
becoming . instance_variable_set ( :@attributes , @attributes )
493
493
becoming . instance_variable_set ( :@mutations_from_database , @mutations_from_database ||= nil )
494
494
becoming . instance_variable_set ( :@new_record , new_record? )
495
+ becoming . instance_variable_set ( :@previously_new_record , previously_new_record? )
495
496
becoming . instance_variable_set ( :@destroyed , destroyed? )
496
497
becoming . errors . copy! ( errors )
497
498
end
Original file line number Diff line number Diff line change @@ -460,6 +460,17 @@ def test_becomes_includes_changed_attributes
460
460
assert_equal %w{ name } , client . changed
461
461
end
462
462
463
+ def test_becomes_preserve_record_status
464
+ company = Company . new ( name : "37signals" )
465
+ client = company . becomes ( Client )
466
+ assert_predicate client , :new_record?
467
+
468
+ company . save
469
+ client = company . becomes ( Client )
470
+ assert_predicate client , :persisted?
471
+ assert_predicate client , :previously_new_record?
472
+ end
473
+
463
474
def test_becomes_initializes_missing_attributes
464
475
company = Company . new ( name : "GrowingCompany" )
465
476
You can’t perform that action at this time.
0 commit comments