File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change
1
+ * Don't allow destroyed object mutation after ` save ` or ` save! ` is called.
2
+
3
+ * Ryuta Kamizono*
4
+
1
5
* Take into account association conditions when deleting through records.
2
6
3
7
Fixes #18424 .
Original file line number Diff line number Diff line change @@ -694,6 +694,7 @@ def _relation_for_itself
694
694
695
695
def create_or_update ( *args , &block )
696
696
_raise_readonly_record_error if readonly?
697
+ return false if destroyed?
697
698
result = new_record? ? _create_record ( &block ) : _update_record ( *args , &block )
698
699
result != false
699
700
end
Original file line number Diff line number Diff line change @@ -599,30 +599,52 @@ def test_update_all_with_non_standard_table_name
599
599
end
600
600
601
601
def test_delete_new_record
602
- client = Client . new
602
+ client = Client . new ( name : "37signals" )
603
603
client . delete
604
604
assert client . frozen?
605
+
606
+ assert_not client . save
607
+ assert_raise ( ActiveRecord ::RecordNotSaved ) { client . save! }
608
+
609
+ assert client . frozen?
610
+ assert_raise ( RuntimeError ) { client . name = "something else" }
605
611
end
606
612
607
613
def test_delete_record_with_associations
608
614
client = Client . find ( 3 )
609
615
client . delete
610
616
assert client . frozen?
611
617
assert_kind_of Firm , client . firm
618
+
619
+ assert_not client . save
620
+ assert_raise ( ActiveRecord ::RecordNotSaved ) { client . save! }
621
+
622
+ assert client . frozen?
612
623
assert_raise ( RuntimeError ) { client . name = "something else" }
613
624
end
614
625
615
626
def test_destroy_new_record
616
- client = Client . new
627
+ client = Client . new ( name : "37signals" )
617
628
client . destroy
618
629
assert client . frozen?
630
+
631
+ assert_not client . save
632
+ assert_raise ( ActiveRecord ::RecordNotSaved ) { client . save! }
633
+
634
+ assert client . frozen?
635
+ assert_raise ( RuntimeError ) { client . name = "something else" }
619
636
end
620
637
621
638
def test_destroy_record_with_associations
622
639
client = Client . find ( 3 )
623
640
client . destroy
624
641
assert client . frozen?
625
642
assert_kind_of Firm , client . firm
643
+
644
+ assert_not client . save
645
+ assert_raise ( ActiveRecord ::RecordNotSaved ) { client . save! }
646
+
647
+ assert client . frozen?
626
648
assert_raise ( RuntimeError ) { client . name = "something else" }
627
649
end
628
650
You can’t perform that action at this time.
0 commit comments