@@ -264,57 +264,6 @@ class BindParameterTest < ActiveRecord::TestCase
264264 coerce_tests! :test_statement_cache_with_find_by
265265 coerce_tests! :test_statement_cache_with_in_clause
266266 coerce_tests! :test_statement_cache_with_sql_string_literal
267-
268- # Same as original coerced test except prepared statements include `EXEC sp_executesql` wrapper.
269- coerce_tests! :test_bind_params_to_sql_with_prepared_statements , :test_bind_params_to_sql_with_unprepared_statements
270- def test_bind_params_to_sql_with_prepared_statements_coerced
271- assert_bind_params_to_sql_coerced ( prepared : true )
272- end
273-
274- def test_bind_params_to_sql_with_unprepared_statements_coerced
275- @connection . unprepared_statement do
276- assert_bind_params_to_sql_coerced ( prepared : false )
277- end
278- end
279-
280- private
281-
282- def assert_bind_params_to_sql_coerced ( prepared :)
283- table = Author . quoted_table_name
284- pk = "#{ table } .#{ Author . quoted_primary_key } "
285-
286- # prepared_statements: true
287- #
288- # SQL to database:
289- # EXEC sp_executesql N'SELECT [authors].* FROM [authors] WHERE [authors].[id] IN (@0, @1, @2) OR [authors].[id] IS NULL)', N'@0 bigint, @1 bigint, @2 bigint', @0 = 1, @1 = 2, @2 = 3
290- #
291- # prepared_statements: false
292- #
293- # SQL to database:
294- # SELECT [authors].* FROM [authors] WHERE ([authors].[id] IN (1, 2, 3) OR [authors].[id] IS NULL)
295- #
296- expected_logged_sql = "SELECT #{ table } .* FROM #{ table } WHERE (#{ pk } IN (#{ bind_params ( 1 ..3 ) } ) OR #{ pk } IS NULL)"
297-
298- authors = Author . where ( id : [ 1 , 2 , 3 , nil ] )
299- assert_equal expected_logged_sql , @connection . to_sql ( authors . arel )
300- assert_queries_match ( expected_logged_sql ) { assert_equal 3 , authors . length }
301-
302- # prepared_statements: true
303- #
304- # SQL to database:
305- # EXEC sp_executesql N'SELECT [authors].* FROM [authors] WHERE [authors].[id] IN (@0, @1, @2)', N'@0 bigint, @1 bigint, @2 bigint', @0 = 1, @1 = 2, @2 = 3
306- #
307- # prepared_statements: false
308- #
309- # SQL to database:
310- # SELECT [authors].* FROM [authors] WHERE [authors].[id] IN (1, 2, 3)
311- #
312- expected_logged_sql = "SELECT #{ table } .* FROM #{ table } WHERE #{ pk } IN (#{ bind_params ( 1 ..3 ) } )"
313-
314- authors = Author . where ( id : [ 1 , 2 , 3 , 9223372036854775808 ] )
315- assert_equal expected_logged_sql , @connection . to_sql ( authors . arel )
316- assert_queries_match ( expected_logged_sql ) { assert_equal 3 , authors . length }
317- end
318267 end
319268end
320269
@@ -2391,66 +2340,6 @@ def test_in_order_of_with_nil_coerced
23912340
23922341require "models/dashboard"
23932342class QueryLogsTest < ActiveRecord ::TestCase
2394- # SQL requires double single-quotes.
2395- coerce_tests! :test_sql_commenter_format
2396- def test_sql_commenter_format_coerced
2397- ActiveRecord ::QueryLogs . tags_formatter = :sqlcommenter
2398- ActiveRecord ::QueryLogs . tags = [ :application ]
2399-
2400- assert_queries_match ( %r{/\* application='active_record'\* /} ) do
2401- Dashboard . first
2402- end
2403- end
2404-
2405- # SQL requires double single-quotes.
2406- coerce_tests! :test_sqlcommenter_format_value
2407- def test_sqlcommenter_format_value_coerced
2408- ActiveRecord ::QueryLogs . tags_formatter = :sqlcommenter
2409-
2410- ActiveRecord ::QueryLogs . tags = [
2411- :application ,
2412- { tracestate : "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7" , custom_proc : -> { "Joe's Shack" } } ,
2413- ]
2414-
2415- assert_queries_match ( %r{custom_proc='Joe%27s%20Shack',tracestate='congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7'\* /} ) do
2416- Dashboard . first
2417- end
2418- end
2419-
2420- # SQL requires double single-quotes.
2421- coerce_tests! :test_sqlcommenter_format_value_string_coercible
2422- def test_sqlcommenter_format_value_string_coercible_coerced
2423- ActiveRecord ::QueryLogs . tags_formatter = :sqlcommenter
2424-
2425- ActiveRecord ::QueryLogs . tags = [
2426- :application ,
2427- { custom_proc : -> { 1234 } } ,
2428- ]
2429-
2430- assert_queries_match ( %r{custom_proc='1234'\* /} ) do
2431- Dashboard . first
2432- end
2433- end
2434-
2435- # SQL requires double single-quotes.
2436- coerce_tests! :test_sqlcommenter_format_allows_string_keys
2437- def test_sqlcommenter_format_allows_string_keys_coerced
2438- ActiveRecord ::QueryLogs . tags_formatter = :sqlcommenter
2439-
2440- ActiveRecord ::QueryLogs . tags = [
2441- :application ,
2442- {
2443- "string" => "value" ,
2444- tracestate : "congo=t61rcWkgMzE,rojo=00f067aa0ba902b7" ,
2445- custom_proc : -> { "Joe's Shack" }
2446- } ,
2447- ]
2448-
2449- assert_queries_match ( %r{custom_proc='Joe%27s%20Shack',string='value',tracestate='congo%3Dt61rcWkgMzE%2Crojo%3D00f067aa0ba902b7'\* /} ) do
2450- Dashboard . first
2451- end
2452- end
2453-
24542343 # Invalid character encoding causes `ActiveRecord::StatementInvalid` error similar to Postgres.
24552344 coerce_tests! :test_invalid_encoding_query
24562345 def test_invalid_encoding_query_coerced
@@ -2699,33 +2588,6 @@ def type_for_attribute_is_not_aware_of_custom_types_coerced
26992588 end
27002589end
27012590
2702- require "models/car"
2703- class ExplainTest < ActiveRecord ::TestCase
2704- # Expected query slightly different from because of 'sp_executesql' and query parameters.
2705- coerce_tests! :test_relation_explain_with_first
2706- def test_relation_explain_with_first_coerced
2707- expected_query = capture_sql {
2708- Car . all . first
2709- } . first [ /(.*?) NEXT/ , 1 ]
2710- message = Car . all . explain . first
2711- assert_match ( /^EXPLAIN/ , message )
2712- assert_match ( expected_query , message )
2713- end
2714-
2715- # Expected query slightly different from because of 'sp_executesql' and query parameters.
2716- coerce_tests! :test_relation_explain_with_last
2717- def test_relation_explain_with_last_coerced
2718- expected_query = capture_sql {
2719- Car . all . last
2720- } . first [ /(.*?) NEXT/ , 1 ]
2721- expected_query = expected_query
2722- message = Car . all . explain . last
2723-
2724- assert_match ( /^EXPLAIN/ , message )
2725- assert_match ( expected_query , message )
2726- end
2727- end
2728-
27292591module ActiveRecord
27302592 module Assertions
27312593 class QueryAssertionsTest < ActiveSupport ::TestCase
0 commit comments