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

module Arel
  describe Join do
    before do
      @relation1 = Array.new([
        [1, 'duck' ],
        [2, 'duck' ],
        [3, 'goose']
      ], [:id, :name])
      @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]))  \
          .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