Skip to content

Commit e439d83

Browse files
committed
Fix how we are checking bind tests, can't use coerce since the test methods are defined in an if block
1 parent 8035c19 commit e439d83

File tree

1 file changed

+24
-53
lines changed

1 file changed

+24
-53
lines changed
Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,33 @@
11
require 'cases/sqlserver_helper'
22
require 'models/topic'
33
require 'models_sqlserver/topic'
4-
5-
class BindParameterTestSqlServer < ActiveRecord::TestCase
6-
7-
COERCED_TESTS = [
8-
:test_binds_are_logged,
9-
:test_binds_are_logged_after_type_cast
10-
]
11-
12-
include SqlserverCoercedTest
13-
14-
fixtures :topics
15-
16-
class LogListener
17-
attr_accessor :calls
18-
19-
def initialize
20-
@calls = []
4+
require 'cases/bind_parameter_test'
5+
6+
# We don't coerce here because these tests are located inside of an if block
7+
# and don't seem to be able to be properly overriden with the coerce
8+
# functionality
9+
module ActiveRecord
10+
class BindParameterTest
11+
def test_binds_are_logged
12+
sub = @connection.substitute_at(@pk, 0)
13+
binds = [[@pk, 1]]
14+
sql = "select * from topics where id = #{sub}"
15+
16+
@connection.exec_query(sql, 'SQL', binds)
17+
18+
message = @listener.calls.find { |args| args[4][:sql].include? sql }
19+
assert_equal binds, message[4][:binds]
2120
end
2221

23-
def call(*args)
24-
calls << args
25-
end
26-
end
22+
def test_binds_are_logged_after_type_cast
23+
sub = @connection.substitute_at(@pk, 0)
24+
binds = [[@pk, "3"]]
25+
sql = "select * from topics where id = #{sub}"
2726

28-
def setup
29-
super
30-
@connection = ActiveRecord::Base.connection
31-
@listener = LogListener.new
32-
@pk = Topic.columns.find { |c| c.primary }
33-
ActiveSupport::Notifications.subscribe('sql.active_record', @listener)
34-
end
27+
@connection.exec_query(sql, 'SQL', binds)
3528

36-
def teardown
37-
ActiveSupport::Notifications.unsubscribe(@listener)
38-
end
39-
40-
def test_coerced_binds_are_logged
41-
sub = @connection.substitute_at(@pk, 0)
42-
binds = [[@pk, 1]]
43-
sql = "select * from topics where id = #{sub}"
44-
45-
@connection.exec_query(sql, 'SQL', binds)
46-
47-
message = @listener.calls.find { |args| args[4][:sql].include? sql }
48-
assert_equal binds, message[4][:binds]
49-
end
50-
51-
def test_coerced_binds_are_logged_after_type_cast
52-
sub = @connection.substitute_at(@pk, 0)
53-
binds = [[@pk, "3"]]
54-
sql = "select * from topics where id = #{sub}"
55-
56-
@connection.exec_query(sql, 'SQL', binds)
57-
58-
message = @listener.calls.find { |args| args[4][:sql].include? sql }
59-
assert_equal [[@pk, 3]], message[4][:binds]
29+
message = @listener.calls.find { |args| args[4][:sql].include? sql }
30+
assert_equal [[@pk, 3]], message[4][:binds]
31+
end
6032
end
61-
6233
end

0 commit comments

Comments
 (0)