Skip to content

Commit 429a441

Browse files
committed
Removed tests that no longer need to be coerced. Added changelog.
1 parent bdef074 commit 429a441

File tree

3 files changed

+8
-140
lines changed

3 files changed

+8
-140
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## Unreleased
2+
3+
#### Fixed
4+
5+
- [#1370](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1370) Fixed query logging so that filter parameters are respected.
6+
17
## v8.0.9
28

39
#### Fixed

test/cases/coerced_tests.rb

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -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
319268
end
320269

@@ -2391,66 +2340,6 @@ def test_in_order_of_with_nil_coerced
23912340

23922341
require "models/dashboard"
23932342
class 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
27002589
end
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-
27292591
module ActiveRecord
27302592
module Assertions
27312593
class QueryAssertionsTest < ActiveSupport::TestCase

test/cases/showplan_test_sqlserver.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class ShowplanTestSQLServer < ActiveRecord::TestCase
2828

2929
it "from array condition using index" do
3030
plan = Car.where(id: [1, 2]).explain.inspect
31-
_(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id]"
31+
_(plan).must_include "SELECT [cars].* FROM [cars] WHERE [cars].[id] IN (@0, @1)"
3232
_(plan).must_include "Clustered Index Seek", "make sure we do not showplan the sp_executesql"
3333
end
3434

3535
it "from array condition" do
3636
plan = Car.where(name: ["honda", "zyke"]).explain.inspect
37-
_(plan).must_include " SELECT [cars].* FROM [cars] WHERE [cars].[name]"
37+
_(plan).must_include " SELECT [cars].* FROM [cars] WHERE [cars].[name] IN (@0, @1)"
3838
_(plan).must_include "Clustered Index Scan", "make sure we do not showplan the sp_executesql"
3939
end
4040
end

0 commit comments

Comments
 (0)