aboutsummaryrefslogtreecommitdiffstats
path: root/spec/engines/memory/unit/relations/join_spec.rb
blob: 93379985cbc674d95d407e372bf96cabac8c992d (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
require 'spec_helper'

module Arel
  describe Join do
    before do
      @relation1 = Array.new([
        [1, 'duck' ],
        [2, 'duck' ],
        [3, 'goose']
      ], [[:id, Attributes::Integer], [:name, Attributes::String]])
      @relation2 = @relation1.alias
    end

    describe InnerJoin do
      describe '#call' do
        it 'combines the two tables where the predicate obtains' do
          @relation1                                    \
            .join(@relation2)                           \
              .on(@relation1[:id].eq(@relation2[:id]))  \
          .tap do |relation|
            rows = relation.call
            rows.length.should == 3
            @relation1.array.zip(rows).each do |tuple, row|
              row.relation.should == relation
              row.tuple.should == (tuple * 2)
            end
          end
        end
      end
    end
  end
end