From 90cd6b91d853dbda55a64125f174b1df27fc587a Mon Sep 17 00:00:00 2001 From: Aidan Haran Date: Wed, 8 Oct 2025 14:00:21 +0100 Subject: [PATCH] Coerce tests --- test/cases/coerced_tests.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/cases/coerced_tests.rb b/test/cases/coerced_tests.rb index caee1e15b..f3ec9de32 100644 --- a/test/cases/coerced_tests.rb +++ b/test/cases/coerced_tests.rb @@ -2959,4 +2959,30 @@ def test_in_batches_executes_range_queries_when_constrained_and_opted_in_into_ra relations.each { |relation| assert_kind_of Post, relation.first } end end + + # Match SQL Server SQL format. + coerce_tests! :test_in_batches_should_unscope_cursor_after_pluck + def test_in_batches_should_unscope_cursor_after_pluck_coerced + all_ids = Post.limit(2).pluck(:id) + found_ids = [] + # only a single clause on id (i.e. not 'id IN (?,?) AND id = ?', but only 'id = ?') + assert_queries_match(/WHERE #{Regexp.escape(quote_table_name("posts.id"))} = \S+ ORDER BY/) do + Post.where(id: all_ids).in_batches(of: 1) do |relation| + found_ids << relation.pick(:id) + end + end + assert_equal all_ids.sort, found_ids + end + + # Match SQL Server SQL format. + coerce_tests! :test_in_batches_loaded_should_unscope_cursor_after_pluck + def test_in_batches_loaded_should_unscope_cursor_after_pluck_coerced + all_ids = Post.limit(2).pluck(:id) + # only a single clause on id (i.e. not 'id IN (?,?) AND id = ?', but only 'id = ?') + assert_queries_match(/WHERE #{Regexp.escape(quote_table_name("posts.id"))} = \S+;/) do + Post.where(id: all_ids).in_batches(of: 1, load: true) do |relation| + relation.delete_all + end + end + end end