Sha256: 2a05deb84c78864ba4bce4229bcceede447ee1a7eaf1315eff897c348a08290f

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require_relative "../helper"

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

      def collect(node)
        @visitor.accept(node, Collectors::SQLString.new)
      end

      def compile(node)
        collect(node).value
      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 test_compile
        sql = compile(ast_with_binds)
        assert_equal 'SELECT FROM "users" WHERE "users"."age" = ? AND "users"."name" = ?', sql
      end

      def test_returned_sql_uses_utf8_encoding
        sql = compile(ast_with_binds)
        assert_equal sql.encoding, Encoding::UTF_8
      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/sql_string_test.rb
ibm_db-5.4.1-x86-mingw32 test/cases/arel/collectors/sql_string_test.rb
ibm_db-5.4.0-x86-mingw32 test/cases/arel/collectors/sql_string_test.rb
ibm_db-5.3.2-x86-mingw32 test/cases/arel/collectors/sql_string_test.rb