Sha256: b4c16dd660c1e2b4b81ecf597b81342412ded56d91891b256061e3f6f91362e3

Contents?: true

Size: 1020 Bytes

Versions: 5

Compression:

Stored size: 1020 Bytes

Contents

# frozen_string_literal: true

require_relative "../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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ibm_db-5.5.0 test/cases/arel/collectors/bind_test.rb
ibm_db-5.4.1 test/cases/arel/collectors/bind_test.rb
ibm_db-5.4.0 test/cases/arel/collectors/bind_test.rb
ibm_db-5.3.2 test/cases/arel/collectors/bind_test.rb
ibm_db-5.3.1 test/cases/arel/collectors/bind_test.rb