aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/arel/nodes/bin_test.rb
blob: ee2ec3cf2f6410d9824de969b0fb9d67120d56f9 (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
# frozen_string_literal: true

require_relative "../helper"

module Arel
  module Nodes
    class TestBin < Arel::Test
      def test_new
        assert Arel::Nodes::Bin.new("zomg")
      end

      def test_default_to_sql
        viz  = Arel::Visitors::ToSql.new Table.engine.connection_pool
        node = Arel::Nodes::Bin.new(Arel.sql("zomg"))
        assert_equal "zomg", viz.accept(node, Collectors::SQLString.new).value
      end

      def test_mysql_to_sql
        viz  = Arel::Visitors::MySQL.new Table.engine.connection_pool
        node = Arel::Nodes::Bin.new(Arel.sql("zomg"))
        assert_equal "BINARY zomg", viz.accept(node, Collectors::SQLString.new).value
      end

      def test_equality_with_same_ivars
        array = [Bin.new("zomg"), Bin.new("zomg")]
        assert_equal 1, array.uniq.size
      end

      def test_inequality_with_different_ivars
        array = [Bin.new("zomg"), Bin.new("zomg!")]
        assert_equal 2, array.uniq.size
      end
    end
  end
end