diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-08-18 14:01:48 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-18 14:01:48 +0900 |
commit | 7612675fb76e1dcfc1c37fe08f951d476cae6d27 (patch) | |
tree | 37055333de0d7fd41d4bc1d5423a67714810498a | |
parent | 893ccb3d37c64b28c27c0f7a5790a69c6dc159ba (diff) | |
download | rails-7612675fb76e1dcfc1c37fe08f951d476cae6d27.tar.gz rails-7612675fb76e1dcfc1c37fe08f951d476cae6d27.tar.bz2 rails-7612675fb76e1dcfc1c37fe08f951d476cae6d27.zip |
Add test cases that class level `destroy`, `delete`, and `update` are affected by scoping (#29997)
I tried to change the expectation in #29976, but it is expected behavior
at least for now. So I added the test cases to prevent anyone change the
expectation.
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index c887f54560..170fd02b6f 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -78,6 +78,16 @@ class PersistenceTest < ActiveRecord::TestCase assert_equal "2 updated", Topic.find(2).content end + def test_class_level_update_is_affected_by_scoping + topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } } + + assert_raise(ActiveRecord::RecordNotFound) do + Topic.where("1=0").scoping { Topic.update(topic_data.keys, topic_data.values) } + end + assert_not_equal "1 updated", Topic.find(1).content + assert_not_equal "2 updated", Topic.find(2).content + end + def test_delete_all assert Topic.count > 0 @@ -912,13 +922,33 @@ class PersistenceTest < ActiveRecord::TestCase assert_raise(ActiveRecord::RecordNotFound) { Reply.find(should_be_destroyed_reply.id) } end + def test_class_level_destroy_is_affected_by_scoping + should_not_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world") + Topic.find(1).replies << should_not_be_destroyed_reply + + 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) } + end + def test_class_level_delete - should_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world") - Topic.find(1).replies << should_be_destroyed_reply + should_not_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world") + Topic.find(1).replies << should_not_be_destroyed_reply Topic.delete(1) assert_raise(ActiveRecord::RecordNotFound) { Topic.find(1) } - assert_nothing_raised { Reply.find(should_be_destroyed_reply.id) } + assert_nothing_raised { Reply.find(should_not_be_destroyed_reply.id) } + end + + def test_class_level_delete_is_affected_by_scoping + should_not_be_destroyed_reply = Reply.create("title" => "hello", "content" => "world") + Topic.find(1).replies << should_not_be_destroyed_reply + + Topic.where("1=0").scoping { Topic.delete(1) } + assert_nothing_raised { Topic.find(1) } + assert_nothing_raised { Reply.find(should_not_be_destroyed_reply.id) } end def test_create_with_custom_timestamps |