@@ -243,6 +243,25 @@ def test_update_date_time_attributes_with_default_timezone_local
243
243
end
244
244
end
245
245
246
+ class HasManyThroughAssociationsTest < ActiveRecord ::TestCase
247
+ # SQL Server does not have query for release_savepoint
248
+ coerce_tests! :test_associate_existing
249
+ def test_associate_existing_coerced
250
+ post = posts ( :thinking )
251
+ person = people ( :david )
252
+
253
+ assert_queries_count ( 2 ) do
254
+ post . people << person
255
+ end
256
+
257
+ assert_queries_count ( 1 ) do
258
+ assert_includes post . people , person
259
+ end
260
+
261
+ assert_includes post . reload . people . reload , person
262
+ end
263
+ end
264
+
246
265
class BelongsToAssociationsTest < ActiveRecord ::TestCase
247
266
# Since @client.firm is a single first/top, and we use FETCH the order clause is used.
248
267
coerce_tests! :test_belongs_to_does_not_use_order_by
@@ -1492,11 +1511,11 @@ def self.search_as_method(term)
1492
1511
}
1493
1512
end
1494
1513
1495
- assert_queries_match ( /LIKE N'20!% !_reduction!_!!' / ) do
1514
+ assert_queries_match ( /LIKE @0 / ) do
1496
1515
searchable_post . search_as_method ( "20% _reduction_!" ) . to_a
1497
1516
end
1498
1517
1499
- assert_queries_match ( /LIKE N'20!% !_reduction!_!!' / ) do
1518
+ assert_queries_match ( /LIKE @0 / ) do
1500
1519
searchable_post . search_as_scope ( "20% _reduction_!" ) . to_a
1501
1520
end
1502
1521
end
@@ -2103,7 +2122,7 @@ def test_merge_doesnt_duplicate_same_clauses_coerced
2103
2122
2104
2123
only_david = Author . where ( "#{ author_id } IN (?)" , david )
2105
2124
2106
- assert_queries_match ( /WHERE \( #{ Regexp . escape ( author_id ) } IN \( 1 \) \) \z / ) do
2125
+ assert_queries_match ( /WHERE \( #{ Regexp . escape ( author_id ) } IN \( @ \d \) \) / ) do
2107
2126
assert_equal [ david ] , only_david . merge ( only_david )
2108
2127
end
2109
2128
end
@@ -2456,6 +2475,25 @@ def test_sqlcommenter_format_value_string_coercible_coerced
2456
2475
end
2457
2476
end
2458
2477
2478
+ # SQL requires double single-quotes.
2479
+ coerce_tests! :test_sqlcommenter_format_allows_string_keys
2480
+ def test_sqlcommenter_format_allows_string_keys_coerced
2481
+ ActiveRecord ::QueryLogs . update_formatter ( :sqlcommenter )
2482
+
2483
+ ActiveRecord ::QueryLogs . tags = [
2484
+ :application ,
2485
+ {
2486
+ "string" => "value" ,
2487
+ tracestate : "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7" ,
2488
+ custom_proc : -> { "Joe's Shack" }
2489
+ } ,
2490
+ ]
2491
+
2492
+ assert_queries_match ( %r{custom_proc=''Joe%27s%20Shack'',string=''value'',tracestate=''congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7''\* /} ) do
2493
+ Dashboard . first
2494
+ end
2495
+ end
2496
+
2459
2497
# Invalid character encoding causes `ActiveRecord::StatementInvalid` error similar to Postgres.
2460
2498
coerce_tests! :test_invalid_encoding_query
2461
2499
def test_invalid_encoding_query_coerced
0 commit comments