Sha256: 56179d174ef745ed6ae57a9f5e0482cd6b8fd9fd17df09ec04ae7cb9cee58c59

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

require_relative "../helper"
require "arel/collectors/substitute_binds"
require "arel/collectors/sql_string"

module Arel
  module Collectors
    class TestSubstituteBindCollector < Arel::Test
      def setup
        @conn = FakeRecord::Base.new
        @visitor = Visitors::ToSql.new @conn.connection
        super
      end

      def ast_with_binds
        table = Table.new(:users)
        manager = Arel::SelectManager.new table
        manager.where(table[:age].eq(Nodes::BindParam.new("hello")))
        manager.where(table[:name].eq(Nodes::BindParam.new("world")))
        manager.ast
      end

      def compile(node, quoter)
        collector = Collectors::SubstituteBinds.new(quoter, Collectors::SQLString.new)
        @visitor.accept(node, collector).value
      end

      def test_compile
        quoter = Object.new
        def quoter.quote(val)
          val.to_s
        end
        sql = compile(ast_with_binds, quoter)
        assert_equal 'SELECT FROM "users" WHERE "users"."age" = hello AND "users"."name" = world', sql
      end

      def test_quoting_is_delegated_to_quoter
        quoter = Object.new
        def quoter.quote(val)
          val.inspect
        end
        sql = compile(ast_with_binds, quoter)
        assert_equal 'SELECT FROM "users" WHERE "users"."age" = "hello" AND "users"."name" = "world"', sql
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ibm_db-5.5.0-x86-mingw32 test/cases/arel/collectors/substitute_bind_collector_test.rb
ibm_db-5.4.1-x86-mingw32 test/cases/arel/collectors/substitute_bind_collector_test.rb
ibm_db-5.4.0-x86-mingw32 test/cases/arel/collectors/substitute_bind_collector_test.rb
ibm_db-5.3.2-x86-mingw32 test/cases/arel/collectors/substitute_bind_collector_test.rb