diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-15 04:30:37 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2018-01-15 04:52:01 +0900 |
commit | 562dd0494a90d9d47849f052e8913f0050f3e494 (patch) | |
tree | 786aa2778e1ba384669b7100e24e16f4af1fa4a9 /activerecord/test | |
parent | f1af27fd9d9101684b26d0dcf2028859d67bec1f (diff) | |
download | rails-562dd0494a90d9d47849f052e8913f0050f3e494.tar.gz rails-562dd0494a90d9d47849f052e8913f0050f3e494.tar.bz2 rails-562dd0494a90d9d47849f052e8913f0050f3e494.zip |
Don't allow destroyed object mutation after `save` or `save!` is called
Currently `object.save` will unfreeze the object, due to
`changes_applied` replaces frozen `@attributes` to new `@attributes`.
Since originally destroyed objects are not allowed to be mutated, `save`
and `save!` should not return success in that case.
Fixes #28563.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 0fa8ea212f..0edca96cf5 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -599,9 +599,15 @@ class PersistenceTest < ActiveRecord::TestCase end def test_delete_new_record - client = Client.new + client = Client.new(name: "37signals") client.delete assert client.frozen? + + assert_not client.save + assert_raise(ActiveRecord::RecordNotSaved) { client.save! } + + assert client.frozen? + assert_raise(RuntimeError) { client.name = "something else" } end def test_delete_record_with_associations @@ -609,13 +615,24 @@ class PersistenceTest < ActiveRecord::TestCase client.delete assert client.frozen? assert_kind_of Firm, client.firm + + assert_not client.save + assert_raise(ActiveRecord::RecordNotSaved) { client.save! } + + assert client.frozen? assert_raise(RuntimeError) { client.name = "something else" } end def test_destroy_new_record - client = Client.new + client = Client.new(name: "37signals") client.destroy assert client.frozen? + + assert_not client.save + assert_raise(ActiveRecord::RecordNotSaved) { client.save! } + + assert client.frozen? + assert_raise(RuntimeError) { client.name = "something else" } end def test_destroy_record_with_associations @@ -623,6 +640,11 @@ class PersistenceTest < ActiveRecord::TestCase client.destroy assert client.frozen? assert_kind_of Firm, client.firm + + assert_not client.save + assert_raise(ActiveRecord::RecordNotSaved) { client.save! } + + assert client.frozen? assert_raise(RuntimeError) { client.name = "something else" } end |