@@ -145,8 +145,27 @@ def test_belongs_to_with_primary_key_joins_on_correct_column_coerced
145
145
146
146
module ActiveRecord
147
147
class BindParameterTest < ActiveRecord ::TestCase
148
- # Never finds `sql` since we use `EXEC sp_executesql` wrappers .
148
+ # Same as original coerced test except log is found using `EXEC sp_executesql` wrapper .
149
149
coerce_tests! :test_binds_are_logged
150
+ def test_binds_are_logged_coerced
151
+ sub = Arel ::Nodes ::BindParam . new ( 1 )
152
+ binds = [ Relation ::QueryAttribute . new ( "id" , 1 , Type ::Value . new ) ]
153
+ sql = "select * from topics where id = #{ sub . to_sql } "
154
+
155
+ @connection . exec_query ( sql , "SQL" , binds )
156
+
157
+ logged_sql = "EXEC sp_executesql N'#{ sql } ', N'#{ sub . to_sql } int', #{ sub . to_sql } = 1"
158
+ message = @subscriber . calls . find { |args | args [ 4 ] [ :sql ] == logged_sql }
159
+
160
+ assert_equal binds , message [ 4 ] [ :binds ]
161
+ end
162
+
163
+ # SQL Server adapter does not use a statement cache as query plans are already reused using `EXEC sp_executesql`.
164
+ coerce_tests! :test_statement_cache
165
+ coerce_tests! :test_statement_cache_with_query_cache
166
+ coerce_tests! :test_statement_cache_with_find_by
167
+ coerce_tests! :test_statement_cache_with_in_clause
168
+ coerce_tests! :test_statement_cache_with_sql_string_literal
150
169
end
151
170
end
152
171
@@ -192,14 +211,14 @@ def test_should_return_decimal_average_of_integer_field_coerced
192
211
def test_limit_is_kept_coerced
193
212
queries = capture_sql_ss { Account . limit ( 1 ) . count }
194
213
assert_equal 1 , queries . length
195
- queries . first . must_match %r{ORDER BY \[ accounts\] \. \[ id\] ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1}
214
+ _ ( queries . first ) . must_match %r{ORDER BY \[ accounts\] \. \[ id\] ASC OFFSET 0 ROWS FETCH NEXT @0 ROWS ONLY.*@0 = 1}
196
215
end
197
216
198
217
coerce_tests! :test_limit_with_offset_is_kept
199
218
def test_limit_with_offset_is_kept_coerced
200
219
queries = capture_sql_ss { Account . limit ( 1 ) . offset ( 1 ) . count }
201
220
assert_equal 1 , queries . length
202
- queries . first . must_match %r{ORDER BY \[ accounts\] \. \[ id\] ASC OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY.*@0 = 1, @1 = 1}
221
+ _ ( queries . first ) . must_match %r{ORDER BY \[ accounts\] \. \[ id\] ASC OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY.*@0 = 1, @1 = 1}
203
222
end
204
223
205
224
# SQL Server needs an alias for the calculated column
@@ -265,7 +284,7 @@ class ColumnAttributesTest < ActiveRecord::TestCase
265
284
def test_add_column_without_limit_coerced
266
285
add_column :test_models , :description , :string , limit : nil
267
286
TestModel . reset_column_information
268
- TestModel . columns_hash [ "description" ] . limit . must_equal 4000
287
+ _ ( TestModel . columns_hash [ "description" ] . limit ) . must_equal 4000
269
288
end
270
289
end
271
290
end
@@ -615,14 +634,14 @@ class PersistenceTest < ActiveRecord::TestCase
615
634
coerce_tests! :test_update_all_doesnt_ignore_order
616
635
def test_update_all_doesnt_ignore_order_coerced
617
636
david , mary = authors ( :david ) , authors ( :mary )
618
- david . id . must_equal 1
619
- mary . id . must_equal 2
620
- david . name . wont_equal mary . name
637
+ _ ( david . id ) . must_equal 1
638
+ _ ( mary . id ) . must_equal 2
639
+ _ ( david . name ) . wont_equal mary . name
621
640
assert_sql ( /UPDATE.*\( SELECT \[ authors\] .\[ id\] FROM \[ authors\] .*ORDER BY \[ authors\] .\[ id\] /i ) do
622
641
Author . where ( '[id] > 1' ) . order ( :id ) . update_all ( name : 'Test' )
623
642
end
624
- david . reload . name . must_equal 'David'
625
- mary . reload . name . must_equal 'Test'
643
+ _ ( david . reload . name ) . must_equal 'David'
644
+ _ ( mary . reload . name ) . must_equal 'Test'
626
645
end
627
646
628
647
# We can not UPDATE identity columns.
0 commit comments