aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/engines/memory/unit/relations/join_spec.rb
blob: df08fd4a96a067b570a527866cdcf051d04179eb (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 File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')

module Arel
  describe Join do
    before do
      @relation1 = Array.new([
        [1, 'duck' ],
        [2, 'duck' ],
        [3, 'goose']
      ], [:id, :name])
      @relation2 = @relation1.alias
      @relation3 = @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]))  \
          .let do |relation|
            relation.call.should == [
              Row.new(relation, [1, 'duck',  1, 'duck' ]),
              Row.new(relation, [2, 'duck',  2, 'duck' ]),
              Row.new(relation, [3, 'goose', 3, 'goose'])
            ]
          end
        end
      end
    end
  end
end