Merge pull request #45671 from fatkodima/in_batches-subquery-test

Add missing test ensuring no subqueries for whole table batching
This commit is contained in:
Jean Boussier 2022-07-27 17:13:23 +02:00 committed by GitHub
commit e1a2c9e441
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -473,6 +473,14 @@ def test_in_batches_executes_range_queries_when_constrained_and_opted_in_into_ra
end
end
def test_in_batches_no_subqueries_for_whole_tables_batching
c = Post.connection
quoted_posts_id = Regexp.escape(c.quote_table_name("posts.id"))
assert_sql(/DELETE FROM #{c.quote_table_name("posts")} WHERE #{quoted_posts_id} > .+ AND #{quoted_posts_id} <=/i) do
Post.in_batches(of: 2).delete_all
end
end
def test_in_batches_shouldnt_execute_query_unless_needed
assert_queries(2) do
Post.in_batches(of: @total) { |relation| assert_kind_of ActiveRecord::Relation, relation }