aboutsummaryrefslogtreecommitdiffstats
path: root/test/nodes/test_table_alias.rb
blob: 4aafd12b79dce943890eed030e5aeea3b8e57024 (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
require 'helper'
require 'ostruct'

module Arel
  module Nodes
    describe 'table alias' do
      it 'has an #engine which delegates to the relation' do
        engine   = 'vroom'
        relation = Table.new(:users, engine)

        node = TableAlias.new relation, :foo
        node.engine.must_equal engine
      end

      describe 'equality' do
        it 'is equal with equal ivars' do
          relation1 = Table.new(:users, 'vroom')
          node1     = TableAlias.new relation1, :foo
          relation2 = Table.new(:users, 'vroom')
          node2     = TableAlias.new relation2, :foo
          array = [node1, node2]
          assert_equal 1, array.uniq.size
        end

        it 'is not equal with different ivars' do
          relation1 = Table.new(:users, 'vroom')
          node1     = TableAlias.new relation1, :foo
          relation2 = Table.new(:users, 'vroom')
          node2     = TableAlias.new relation2, :bar
          array = [node1, node2]
          assert_equal 2, array.uniq.size
        end
      end
    end
  end
end