aboutsummaryrefslogtreecommitdiffstats
path: root/test/visitors/test_bind_visitor.rb
blob: 92e5d1612cb68ce087051f4fe378251529a3378a (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
require 'helper'
require 'arel/visitors/bind_visitor'

module Arel
  module Visitors
    class TestBindVisitor < MiniTest::Unit::TestCase
      def test_visitor_yields_on_binds
        visitor = Class.new(Arel::Visitors::Visitor) {
          def initialize omg
          end

          include Arel::Visitors::BindVisitor
        }.new nil

        bp = Nodes::BindParam.new 'omg'
        called = false
        visitor.accept(bp) { called = true }
        assert called
      end

      def test_visitor_only_yields_on_binds
        visitor = Class.new(Arel::Visitors::Visitor) {
          def initialize omg
          end

          include Arel::Visitors::BindVisitor
        }.new(nil)

        bp = Arel.sql 'omg'
        called = false

        assert_raises(TypeError) {
          visitor.accept(bp) { called = true }
        }
        refute called
      end
    end
  end
end