diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-19 20:10:51 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-12-19 20:27:10 +0900 |
commit | 9e7260da1bdc0770cf4ac547120c85ab93ff3d48 (patch) | |
tree | c2b1c68bcb8d49245788a9e4484b1b69baad3eb4 /activerecord/test | |
parent | 1118e2c28913be29d03b8a119cb086fe15dacc39 (diff) | |
download | rails-9e7260da1bdc0770cf4ac547120c85ab93ff3d48.tar.gz rails-9e7260da1bdc0770cf4ac547120c85ab93ff3d48.tar.bz2 rails-9e7260da1bdc0770cf4ac547120c85ab93ff3d48.zip |
Using subselect for `delete_all` with `limit` or `offset`
Arel doesn't support subselect generation for DELETE unlike UPDATE yet,
but we already have that generation in connection adapters. We can
simply use the subselect generated by that one.
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/persistence_test.rb | 20 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 2 |
2 files changed, 20 insertions, 2 deletions
diff --git a/activerecord/test/cases/persistence_test.rb b/activerecord/test/cases/persistence_test.rb index 3440781fee..07c4a17fb1 100644 --- a/activerecord/test/cases/persistence_test.rb +++ b/activerecord/test/cases/persistence_test.rb @@ -76,6 +76,26 @@ class PersistenceTest < ActiveRecord::TestCase assert_equal "bulk update!", posts(:thinking).body assert_not_equal "bulk update!", posts(:welcome).body end + + def test_delete_all_with_order_and_limit_deletes_subset_only + author = authors(:david) + limited_posts = Post.where(author: author).order(:id).limit(1) + assert_equal 1, limited_posts.size + assert_equal 2, limited_posts.limit(2).size + assert_equal 1, limited_posts.delete_all + assert_raise(ActiveRecord::RecordNotFound) { posts(:welcome) } + assert posts(:thinking) + end + + def test_delete_all_with_order_and_limit_and_offset_deletes_subset_only + author = authors(:david) + limited_posts = Post.where(author: author).order(:id).limit(1).offset(1) + assert_equal 1, limited_posts.size + assert_equal 2, limited_posts.limit(2).size + assert_equal 1, limited_posts.delete_all + assert_raise(ActiveRecord::RecordNotFound) { posts(:thinking) } + assert posts(:welcome) + end end def test_update_many diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 675aafabda..915ff03c2c 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -896,11 +896,9 @@ class RelationTest < ActiveRecord::TestCase end def test_delete_all_with_unpermitted_relation_raises_error - assert_raises(ActiveRecord::ActiveRecordError) { Author.limit(10).delete_all } assert_raises(ActiveRecord::ActiveRecordError) { Author.distinct.delete_all } assert_raises(ActiveRecord::ActiveRecordError) { Author.group(:name).delete_all } assert_raises(ActiveRecord::ActiveRecordError) { Author.having("SUM(id) < 3").delete_all } - assert_raises(ActiveRecord::ActiveRecordError) { Author.offset(10).delete_all } end def test_select_with_aggregates |