Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading