blob: 4532ab6213c5ba281aece40d6df454284124f89a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
require 'cases/helper'
require 'models/topic'
module ActiveRecord
class BindParameterTest < ActiveRecord::TestCase
class LogListener
attr_accessor :calls
def initialize
@calls = []
end
def call(*args)
calls << args
end
end
fixtures :topics
def setup
super
@connection = ActiveRecord::Base.connection
@listener = LogListener.new
@pk = Topic.columns.find { |c| c.primary }
ActiveSupport::Notifications.subscribe('sql.active_record', @listener)
end
def teardown
ActiveSupport::Notifications.unsubscribe(@listener)
end
def test_binds_are_logged
# FIXME: use skip with minitest
return unless @connection.supports_statement_cache?
sub = @connection.substitute_for(@pk, [])
binds = [[@pk, 1]]
sql = "select * from topics where id = #{sub}"
@connection.exec_query(sql, 'SQL', binds)
message = @listener.calls.find { |args| args[4][:sql] == sql }
assert_equal binds, message[4][:binds]
end
def test_find_one_uses_binds
# FIXME: use skip with minitest
return unless @connection.supports_statement_cache?
Topic.find(1)
binds = [[@pk, 1]]
message = @listener.calls.find { |args| args[4][:binds] == binds }
assert message, 'expected a message with binds'
end
end
end
|