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
24 changes: 24 additions & 0 deletions test/cases/coerced_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,30 @@ def test_insert_all_coerced
end
end

require "models/citation"
class EagerLoadingTooManyIdsTest < ActiveRecord::TestCase
fixtures :citations

# Original Rails test fails with SQL Server error message "The query processor ran out of internal resources and
# could not produce a query plan". This error goes away if you change database compatibility level to 110 (SQL 2012)
# (see https://www.mssqltips.com/sqlservertip/5279/sql-server-error-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan/).
# However, you cannot change the compatibility level during a test. The purpose of the test is to ensure that an
# unprepared statement is used if the number of values exceeds the adapter's `bind_params_length`. The coerced test
# still does this as there will be 32,768 remaining citation records in the database and the `bind_params_length` of
# adapter is 2,098.
coerce_tests! :test_eager_loading_too_many_ids
def test_eager_loading_too_many_ids_coerced
# Remove excess records.
Citation.limit(32768).order(id: :desc).delete_all

# Perform test
citation_count = Citation.count
assert_sql(/WHERE \[citations\]\.\[id\] IN \(0, 1/) do
assert_equal citation_count, Citation.eager_load(:citations).offset(0).size
end
end
end

class LogSubscriberTest < ActiveRecord::TestCase
# Call original test from coerced test. Fixes issue on CI with Rails installed as a gem.
coerce_tests! :test_vebose_query_logs
Expand Down