blob: 5171bbe57caad0902634784f01b3897bbcd224e2 (
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
57
58
59
60
61
62
63
64
65
66
|
require 'helper'
require 'arel/visitors/bind_visitor'
require 'support/fake_record'
module Arel
module Visitors
class TestBindVisitor < Arel::Test
attr_reader :collector
def setup
@collector = Collectors::SQLString.new
super
end
##
# Tests visit_Arel_Nodes_Assignment correctly
# substitutes binds with values from block
def test_assignment_binds_are_substituted
table = Table.new(:users)
um = Arel::UpdateManager.new Table.engine
bp = Nodes::BindParam.new '?'
um.set [[table[:name], bp]]
visitor = Class.new(Arel::Visitors::ToSql) {
include Arel::Visitors::BindVisitor
}.new Table.engine.connection
assignment = um.ast.values[0]
actual = visitor.accept(assignment, collector) {
"replace"
}
assert actual
value = actual.value
assert_like "\"name\" = replace", value
end
def test_visitor_yields_on_binds
visitor = Class.new(Arel::Visitors::ToSql) {
def initialize omg
end
include Arel::Visitors::BindVisitor
}.new nil
bp = Nodes::BindParam.new 'omg'
called = false
visitor.accept(bp, collector) { called = true }
assert called
end
def test_visitor_only_yields_on_binds
visitor = Class.new(Arel::Visitors::ToSql) {
def initialize omg
end
include Arel::Visitors::BindVisitor
}.new(nil)
bp = Arel.sql 'omg'
called = false
visitor.accept(bp, collector) { called = true }
refute called
end
end
end
end
|