aboutsummaryrefslogtreecommitdiffstats
path: root/test/collectors/test_bind.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/collectors/test_bind.rb')
-rw-r--r--test/collectors/test_bind.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/collectors/test_bind.rb b/test/collectors/test_bind.rb
new file mode 100644
index 0000000000..6b4b651cf7
--- /dev/null
+++ b/test/collectors/test_bind.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+require 'helper'
+
+require 'arel/collectors/bind'
+
+module Arel
+ module Collectors
+ class TestBind < Arel::Test
+ def setup
+ @conn = FakeRecord::Base.new
+ @visitor = Visitors::ToSql.new @conn.connection
+ super
+ end
+
+ def collect node
+ @visitor.accept(node, Collectors::Bind.new)
+ end
+
+ def compile node
+ collect(node).value
+ end
+
+ def ast_with_binds bvs
+ table = Table.new(:users)
+ manager = Arel::SelectManager.new table
+ manager.where(table[:age].eq(Nodes::BindParam.new(bvs.shift)))
+ manager.where(table[:name].eq(Nodes::BindParam.new(bvs.shift)))
+ manager.ast
+ end
+
+ def test_compile_gathers_all_bind_params
+ binds = compile(ast_with_binds(["hello", "world"]))
+ assert_equal ["hello", "world"], binds
+
+ binds = compile(ast_with_binds(["hello2", "world3"]))
+ assert_equal ["hello2", "world3"], binds
+ end
+ end
+ end
+end