diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-01 11:49:36 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-01 12:49:46 +0900 |
commit | 0dc3b6535dfb8127f568bb4abc2fb09118ce4b96 (patch) | |
tree | ef8e9543dd355489af3ff8ecc668dcecd99efdbc /activerecord/test | |
parent | 81b2aed360221a2cb5419cc1e5fd697961a183a6 (diff) | |
download | rails-0dc3b6535dfb8127f568bb4abc2fb09118ce4b96.tar.gz rails-0dc3b6535dfb8127f568bb4abc2fb09118ce4b96.tar.bz2 rails-0dc3b6535dfb8127f568bb4abc2fb09118ce4b96.zip |
Maintain raising `RecordNotFound` for class level `update` and` destroy`
In 35836019, class level `update` and `destroy` suppressed
`RecordNotFound` to ensure returning affected objects. But
`RecordNotFound` is a common exception caught by a `rescue_from`
handler. So changing the behavior when a typical `params[:id]` is passed
has a compatibility problem. The previous behavior should not be
changed.
Fixes #31301.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index f088c064f5..643032e7cf 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -473,10 +473,18 @@ class PersistenceTest < ActiveRecord::TestCase assert_raise(ActiveRecord::RecordNotFound) { Topic.find(topic.id) } end - def test_record_not_found_exception + def test_find_raises_record_not_found_exception assert_raise(ActiveRecord::RecordNotFound) { Topic.find(99999) } end + def test_update_raises_record_not_found_exception + assert_raise(ActiveRecord::RecordNotFound) { Topic.update(99999, approved: true) } + end + + def test_destroy_raises_record_not_found_exception + assert_raise(ActiveRecord::RecordNotFound) { Topic.destroy(99999) } + end + def test_update_all assert_equal Topic.count, Topic.update_all("content = 'bulk updated!'") assert_equal "bulk updated!", Topic.find(1).content @@ -938,7 +946,9 @@ class PersistenceTest < ActiveRecord::TestCase should_not_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world") Topic.find(1).replies << should_not_be_destroyed_reply - assert_nil Topic.where("1=0").scoping { Topic.destroy(1) } + assert_raise(ActiveRecord::RecordNotFound) do + Topic.where("1=0").scoping { Topic.destroy(1) } + end assert_nothing_raised { Topic.find(1) } assert_nothing_raised { Reply.find(should_not_be_destroyed_reply.id) } |