Skip to content

Commit 66db048

Browse files
authored
Rails 6: Coerce eagerload too many IDs test (#798)
* Coerce test to managable number of records * Assert that unprepared statement being used * Updated test * Fix test
1 parent 6bdfc09 commit 66db048

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test/cases/coerced_tests.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,7 @@ class EnumTest < ActiveRecord::TestCase
14071407

14081408

14091409

1410+
14101411
require 'models/task'
14111412
class QueryCacheExpiryTest < ActiveRecord::TestCase
14121413

@@ -1437,5 +1438,28 @@ def test_insert_all_coerced
14371438
Task.cache { Task.upsert_all([{ starting: Time.now }]) }
14381439
end
14391440
end
1441+
end
1442+
14401443

1444+
1445+
require 'models/citation'
1446+
class EagerLoadingTooManyIdsTest < ActiveRecord::TestCase
1447+
# Original Rails test fails with SQL Server error message "The query processor ran out of internal resources and
1448+
# could not produce a query plan". This error goes away if you change database compatibility level to 110 (SQL 2012)
1449+
# (see https://www.mssqltips.com/sqlservertip/5279/sql-server-error-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan/).
1450+
# However, you cannot change the compatibility level during a test. The purpose of the test is to ensure that an
1451+
# unprepared statement is used if the number of values exceeds the adapter's `bind_params_length`. The coerced test
1452+
# still does this as there will be 32,768 remaining citation records in the database and the `bind_params_length` of
1453+
# adapter is 2,098.
1454+
coerce_tests! :test_eager_loading_too_may_ids
1455+
def test_eager_loading_too_may_ids_coerced
1456+
# Remove excess records.
1457+
Citation.limit(32768).order(id: :desc).delete_all
1458+
1459+
# Perform test
1460+
citation_count = Citation.count
1461+
assert_sql(/WHERE \(\[citations\]\.\[id\] IN \(0, 1/) do
1462+
assert_equal citation_count, Citation.eager_load(:citations).offset(0).size
1463+
end
1464+
end
14411465
end

0 commit comments

Comments
 (0)