@@ -260,7 +260,7 @@ def test_belongs_to_with_primary_key_joins_on_correct_column_coerced
260
260
def test_belongs_to_coerced
261
261
client = Client . find ( 3 )
262
262
first_firm = companies ( :first_firm )
263
- assert_sql ( /FETCH NEXT @(\d ) ROWS ONLY(.)*@\1 = 1/ ) do
263
+ assert_queries_match ( /FETCH NEXT @(\d ) ROWS ONLY(.)*@\1 = 1/ ) do
264
264
assert_equal first_firm , client . firm
265
265
assert_equal first_firm . name , client . firm . name
266
266
end
@@ -323,7 +323,7 @@ def assert_bind_params_to_sql_coerced(prepared:)
323
323
324
324
authors = Author . where ( id : [ 1 , 2 , 3 , nil ] )
325
325
assert_equal sql_unprepared , @connection . to_sql ( authors . arel )
326
- assert_sql ( prepared ? sql_prepared : sql_unprepared ) { assert_equal 3 , authors . length }
326
+ assert_queries_match ( prepared ? sql_prepared : sql_unprepared ) { assert_equal 3 , authors . length }
327
327
328
328
# prepared_statements: true
329
329
#
@@ -338,7 +338,7 @@ def assert_bind_params_to_sql_coerced(prepared:)
338
338
339
339
authors = Author . where ( id : [ 1 , 2 , 3 , 9223372036854775808 ] )
340
340
assert_equal sql_unprepared , @connection . to_sql ( authors . arel )
341
- assert_sql ( prepared ? sql_prepared : sql_unprepared ) { assert_equal 3 , authors . length }
341
+ assert_queries_match ( prepared ? sql_prepared : sql_unprepared ) { assert_equal 3 , authors . length }
342
342
end
343
343
end
344
344
end
@@ -947,9 +947,9 @@ class FinderTest < ActiveRecord::TestCase
947
947
# Assert SQL Server limit implementation
948
948
coerce_tests! :test_take_and_first_and_last_with_integer_should_use_sql_limit
949
949
def test_take_and_first_and_last_with_integer_should_use_sql_limit_coerced
950
- assert_sql ( /OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.* @0 = 3/ ) { Topic . take ( 3 ) . entries }
951
- assert_sql ( /OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.* @0 = 2/ ) { Topic . first ( 2 ) . entries }
952
- assert_sql ( /OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.* @0 = 5/ ) { Topic . last ( 5 ) . entries }
950
+ assert_queries_match ( /OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.* @0 = 3/ ) { Topic . take ( 3 ) . entries }
951
+ assert_queries_match ( /OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.* @0 = 2/ ) { Topic . first ( 2 ) . entries }
952
+ assert_queries_match ( /OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.* @0 = 5/ ) { Topic . last ( 5 ) . entries }
953
953
end
954
954
955
955
# This fails only when run in the full test suite task. Just taking it out of the mix.
@@ -980,31 +980,31 @@ def test_condition_local_time_interpolation_with_default_timezone_utc_coerced
980
980
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
981
981
coerce_tests! :test_include_on_unloaded_relation_with_match
982
982
def test_include_on_unloaded_relation_with_match_coerced
983
- assert_sql ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
983
+ assert_queries_match ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
984
984
assert_equal true , Customer . where ( name : "David" ) . include? ( customers ( :david ) )
985
985
end
986
986
end
987
987
988
988
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
989
989
coerce_tests! :test_include_on_unloaded_relation_without_match
990
990
def test_include_on_unloaded_relation_without_match_coerced
991
- assert_sql ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
991
+ assert_queries_match ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
992
992
assert_equal false , Customer . where ( name : "David" ) . include? ( customers ( :mary ) )
993
993
end
994
994
end
995
995
996
996
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
997
997
coerce_tests! :test_member_on_unloaded_relation_with_match
998
998
def test_member_on_unloaded_relation_with_match_coerced
999
- assert_sql ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
999
+ assert_queries_match ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
1000
1000
assert_equal true , Customer . where ( name : "David" ) . member? ( customers ( :david ) )
1001
1001
end
1002
1002
end
1003
1003
1004
1004
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
1005
1005
coerce_tests! :test_member_on_unloaded_relation_without_match
1006
1006
def test_member_on_unloaded_relation_without_match_coerced
1007
- assert_sql ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
1007
+ assert_queries_match ( /1 AS one.*FETCH NEXT @2 ROWS ONLY.*@2 = 1/ ) do
1008
1008
assert_equal false , Customer . where ( name : "David" ) . member? ( customers ( :mary ) )
1009
1009
end
1010
1010
end
@@ -1019,7 +1019,7 @@ def test_implicit_order_column_is_configurable_coerced
1019
1019
assert_equal topics ( :third ) , Topic . last
1020
1020
1021
1021
c = Topic . lease_connection
1022
- assert_sql ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.title" ) ) } DESC, #{ Regexp . escape ( c . quote_table_name ( "topics.id" ) ) } DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i ) {
1022
+ assert_queries_match ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.title" ) ) } DESC, #{ Regexp . escape ( c . quote_table_name ( "topics.id" ) ) } DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i ) {
1023
1023
Topic . last
1024
1024
}
1025
1025
ensure
@@ -1033,7 +1033,7 @@ def test_implicit_order_set_to_primary_key_coerced
1033
1033
Topic . implicit_order_column = "id"
1034
1034
1035
1035
c = Topic . lease_connection
1036
- assert_sql ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.id" ) ) } DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i ) {
1036
+ assert_queries_match ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.id" ) ) } DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i ) {
1037
1037
Topic . last
1038
1038
}
1039
1039
ensure
@@ -1048,7 +1048,7 @@ def test_implicit_order_for_model_without_primary_key_coerced
1048
1048
1049
1049
c = NonPrimaryKey . lease_connection
1050
1050
1051
- assert_sql ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "non_primary_keys.created_at" ) ) } DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i ) {
1051
+ assert_queries_match ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "non_primary_keys.created_at" ) ) } DESC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1/i ) {
1052
1052
NonPrimaryKey . last
1053
1053
}
1054
1054
ensure
@@ -1058,7 +1058,7 @@ def test_implicit_order_for_model_without_primary_key_coerced
1058
1058
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
1059
1059
coerce_tests! :test_member_on_unloaded_relation_with_composite_primary_key
1060
1060
def test_member_on_unloaded_relation_with_composite_primary_key_coerced
1061
- assert_sql ( /1 AS one.* FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/ ) do
1061
+ assert_queries_match ( /1 AS one.* FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/ ) do
1062
1062
book = cpk_books ( :cpk_great_author_first_book )
1063
1063
assert Cpk ::Book . where ( title : "The first book" ) . member? ( book )
1064
1064
end
@@ -1073,7 +1073,7 @@ def test_implicit_order_column_prepends_query_constraints_coerced
1073
1073
quoted_color = Regexp . escape ( c . quote_table_name ( "clothing_items.color" ) )
1074
1074
quoted_descrption = Regexp . escape ( c . quote_table_name ( "clothing_items.description" ) )
1075
1075
1076
- assert_sql ( /ORDER BY #{ quoted_descrption } ASC, #{ quoted_type } ASC, #{ quoted_color } ASC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1076
+ assert_queries_match ( /ORDER BY #{ quoted_descrption } ASC, #{ quoted_type } ASC, #{ quoted_color } ASC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1077
1077
assert_kind_of ClothingItem , ClothingItem . first
1078
1078
end
1079
1079
ensure
@@ -1087,7 +1087,7 @@ def test_implicit_order_column_prepends_query_constraints_coerced
1087
1087
quoted_type = Regexp . escape ( c . quote_table_name ( "clothing_items.clothing_type" ) )
1088
1088
quoted_color = Regexp . escape ( c . quote_table_name ( "clothing_items.color" ) )
1089
1089
1090
- assert_sql ( /ORDER BY #{ quoted_type } DESC, #{ quoted_color } DESC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1090
+ assert_queries_match ( /ORDER BY #{ quoted_type } DESC, #{ quoted_color } DESC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1091
1091
assert_kind_of ClothingItem , ClothingItem . last
1092
1092
end
1093
1093
end
@@ -1099,7 +1099,7 @@ def test_implicit_order_column_prepends_query_constraints_coerced
1099
1099
quoted_type = Regexp . escape ( c . quote_table_name ( "clothing_items.clothing_type" ) )
1100
1100
quoted_color = Regexp . escape ( c . quote_table_name ( "clothing_items.color" ) )
1101
1101
1102
- assert_sql ( /ORDER BY #{ quoted_type } ASC, #{ quoted_color } ASC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1102
+ assert_queries_match ( /ORDER BY #{ quoted_type } ASC, #{ quoted_color } ASC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1103
1103
assert_kind_of ClothingItem , ClothingItem . first
1104
1104
end
1105
1105
end
@@ -1112,7 +1112,7 @@ def test_implicit_order_column_reorders_query_constraints_coerced
1112
1112
quoted_type = Regexp . escape ( c . quote_table_name ( "clothing_items.clothing_type" ) )
1113
1113
quoted_color = Regexp . escape ( c . quote_table_name ( "clothing_items.color" ) )
1114
1114
1115
- assert_sql ( /ORDER BY #{ quoted_color } ASC, #{ quoted_type } ASC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1115
+ assert_queries_match ( /ORDER BY #{ quoted_color } ASC, #{ quoted_type } ASC OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/i ) do
1116
1116
assert_kind_of ClothingItem , ClothingItem . first
1117
1117
end
1118
1118
ensure
@@ -1122,7 +1122,7 @@ def test_implicit_order_column_reorders_query_constraints_coerced
1122
1122
# Check for `FETCH NEXT x ROWS` rather then `LIMIT`.
1123
1123
coerce_tests! :test_include_on_unloaded_relation_with_composite_primary_key
1124
1124
def test_include_on_unloaded_relation_with_composite_primary_key_coerced
1125
- assert_sql ( /1 AS one.*OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/ ) do
1125
+ assert_queries_match ( /1 AS one.*OFFSET 0 ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1/ ) do
1126
1126
book = cpk_books ( :cpk_great_author_first_book )
1127
1127
assert Cpk ::Book . where ( title : "The first book" ) . include? ( book )
1128
1128
end
@@ -1132,11 +1132,11 @@ def test_include_on_unloaded_relation_with_composite_primary_key_coerced
1132
1132
coerce_tests! :test_nth_to_last_with_order_uses_limit
1133
1133
def test_nth_to_last_with_order_uses_limit_coerced
1134
1134
c = Topic . lease_connection
1135
- assert_sql ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.id" ) ) } DESC OFFSET @(\d ) ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1.*@\2 = 1/i ) do
1135
+ assert_queries_match ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.id" ) ) } DESC OFFSET @(\d ) ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1.*@\2 = 1/i ) do
1136
1136
Topic . second_to_last
1137
1137
end
1138
1138
1139
- assert_sql ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.updated_at" ) ) } DESC OFFSET @(\d ) ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1.*@\2 = 1/i ) do
1139
+ assert_queries_match ( /ORDER BY #{ Regexp . escape ( c . quote_table_name ( "topics.updated_at" ) ) } DESC OFFSET @(\d ) ROWS FETCH NEXT @(\d ) ROWS ONLY.*@\1 = 1.*@\2 = 1/i ) do
1140
1140
Topic . order ( :updated_at ) . second_to_last
1141
1141
end
1142
1142
end
@@ -1184,7 +1184,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
1184
1184
def test_has_one_coerced
1185
1185
firm = companies ( :first_firm )
1186
1186
first_account = Account . find ( 1 )
1187
- assert_sql ( /FETCH NEXT @(\d ) ROWS ONLY(.)*@\1 = 1/ ) do
1187
+ assert_queries_match ( /FETCH NEXT @(\d ) ROWS ONLY(.)*@\1 = 1/ ) do
1188
1188
assert_equal first_account , firm . account
1189
1189
assert_equal first_account . credit_limit , firm . account . credit_limit
1190
1190
end
@@ -1196,7 +1196,7 @@ class HasOneThroughAssociationsTest < ActiveRecord::TestCase
1196
1196
coerce_tests! :test_has_one_through_executes_limited_query
1197
1197
def test_has_one_through_executes_limited_query_coerced
1198
1198
boring_club = clubs ( :boring_club )
1199
- assert_sql ( /FETCH NEXT @(\d ) ROWS ONLY(.)*@\1 = 1/ ) do
1199
+ assert_queries_match ( /FETCH NEXT @(\d ) ROWS ONLY(.)*@\1 = 1/ ) do
1200
1200
assert_equal boring_club , @member . general_club
1201
1201
end
1202
1202
end
@@ -1257,7 +1257,7 @@ def test_update_all_doesnt_ignore_order_coerced
1257
1257
_ ( david . id ) . must_equal 1
1258
1258
_ ( mary . id ) . must_equal 2
1259
1259
_ ( david . name ) . wont_equal mary . name
1260
- assert_sql ( /UPDATE.*\( SELECT \[ authors\] .\[ id\] FROM \[ authors\] .*ORDER BY \[ authors\] .\[ id\] /i ) do
1260
+ assert_queries_match ( /UPDATE.*\( SELECT \[ authors\] .\[ id\] FROM \[ authors\] .*ORDER BY \[ authors\] .\[ id\] /i ) do
1261
1261
Author . where ( "[id] > 1" ) . order ( :id ) . update_all ( name : "Test" )
1262
1262
end
1263
1263
_ ( david . reload . name ) . must_equal "David"
@@ -1436,15 +1436,15 @@ def test_having_with_binds_for_both_where_and_having
1436
1436
# Find any limit via our expression.
1437
1437
coerce_tests! %r{relations don't load all records in #inspect}
1438
1438
def test_relations_dont_load_all_records_in_inspect_coerced
1439
- assert_sql ( /NEXT @0 ROWS.*@0 = \d +/ ) do
1439
+ assert_queries_match ( /NEXT @0 ROWS.*@0 = \d +/ ) do
1440
1440
Post . all . inspect
1441
1441
end
1442
1442
end
1443
1443
1444
1444
# Find any limit via our expression.
1445
1445
coerce_tests! %r{relations don't load all records in #pretty_print}
1446
1446
def test_relations_dont_load_all_records_in_pretty_print_coerced
1447
- assert_sql ( /FETCH NEXT @(\d ) ROWS ONLY/ ) do
1447
+ assert_queries_match ( /FETCH NEXT @(\d ) ROWS ONLY/ ) do
1448
1448
PP . pp Post . all , StringIO . new # avoid outputting.
1449
1449
end
1450
1450
end
@@ -1516,11 +1516,11 @@ def self.search_as_method(term)
1516
1516
}
1517
1517
end
1518
1518
1519
- assert_sql ( /LIKE N'20!% !_reduction!_!!'/ ) do
1519
+ assert_queries_match ( /LIKE N'20!% !_reduction!_!!'/ ) do
1520
1520
searchable_post . search_as_method ( "20% _reduction_!" ) . to_a
1521
1521
end
1522
1522
1523
- assert_sql ( /LIKE N'20!% !_reduction!_!!'/ ) do
1523
+ assert_queries_match ( /LIKE N'20!% !_reduction!_!!'/ ) do
1524
1524
searchable_post . search_as_scope ( "20% _reduction_!" ) . to_a
1525
1525
end
1526
1526
end
@@ -2125,13 +2125,13 @@ def test_merge_doesnt_duplicate_same_clauses_coerced
2125
2125
non_mary_and_bob = Author . where . not ( id : [ mary , bob ] )
2126
2126
2127
2127
author_id = Author . connection . quote_table_name ( "authors.id" )
2128
- assert_sql ( /WHERE #{ Regexp . escape ( author_id ) } NOT IN \( (@\d ), \g <1>\) '/ ) do
2128
+ assert_queries_match ( /WHERE #{ Regexp . escape ( author_id ) } NOT IN \( (@\d ), \g <1>\) '/ ) do
2129
2129
assert_equal [ david ] , non_mary_and_bob . merge ( non_mary_and_bob )
2130
2130
end
2131
2131
2132
2132
only_david = Author . where ( "#{ author_id } IN (?)" , david )
2133
2133
2134
- assert_sql ( /WHERE \( #{ Regexp . escape ( author_id ) } IN \( 1\) \) \z / ) do
2134
+ assert_queries_match ( /WHERE \( #{ Regexp . escape ( author_id ) } IN \( 1\) \) \z / ) do
2135
2135
assert_equal [ david ] , only_david . merge ( only_david )
2136
2136
end
2137
2137
end
@@ -2253,7 +2253,7 @@ def test_eager_loading_too_many_ids_coerced
2253
2253
2254
2254
# Perform test
2255
2255
citation_count = Citation . count
2256
- assert_sql ( /WHERE \[ citations\] \. \[ id\] IN \( 0, 1/ ) do
2256
+ assert_queries_match ( /WHERE \[ citations\] \. \[ id\] IN \( 0, 1/ ) do
2257
2257
assert_equal citation_count , Citation . eager_load ( :citations ) . offset ( 0 ) . size
2258
2258
end
2259
2259
end
@@ -2449,7 +2449,7 @@ class QueryLogsTest < ActiveRecord::TestCase
2449
2449
coerce_tests! :test_sql_commenter_format
2450
2450
def test_sql_commenter_format_coerced
2451
2451
ActiveRecord ::QueryLogs . update_formatter ( :sqlcommenter )
2452
- assert_sql ( %r{/\* application=''active_record''\* /} ) do
2452
+ assert_queries_match ( %r{/\* application=''active_record''\* /} ) do
2453
2453
Dashboard . first
2454
2454
end
2455
2455
end
@@ -2464,7 +2464,7 @@ def test_sqlcommenter_format_value_coerced
2464
2464
{ tracestate : "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7" , custom_proc : -> { "Joe's Shack" } } ,
2465
2465
]
2466
2466
2467
- assert_sql ( %r{custom_proc=''Joe%27s%20Shack'',tracestate=''congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7''\* /} ) do
2467
+ assert_queries_match ( %r{custom_proc=''Joe%27s%20Shack'',tracestate=''congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7''\* /} ) do
2468
2468
Dashboard . first
2469
2469
end
2470
2470
end
@@ -2479,7 +2479,7 @@ def test_sqlcommenter_format_value_string_coercible_coerced
2479
2479
{ custom_proc : -> { 1234 } } ,
2480
2480
]
2481
2481
2482
- assert_sql ( %r{custom_proc=''1234''\* /} ) do
2482
+ assert_queries_match ( %r{custom_proc=''1234''\* /} ) do
2483
2483
Dashboard . first
2484
2484
end
2485
2485
end
0 commit comments