aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/engines/memory/integration/joins/cross_engine_spec.rb
blob: dd923ee6ebf8172234858993d55aacc92591f207 (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 File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')

module Arel
  describe Join do
    before do
      @users = Array.new([
        [1, 'bryan' ],
        [2, 'emilio' ],
        [3, 'nick']
      ], [:id, :name])
      @photos = Table.new(:photos)
      @photos.delete
      @photos                                                                              \
        .insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6) \
        .insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42)
    end
    
    it 'joins across engines' do
      @users                                         \
        .join(@photos)                               \
          .on(@users[:id].eq(@photos[:user_id]))     \
        .project(@users[:name], @photos[:camera_id]) \
      .let do |relation|
        relation.call.should == [
          Row.new(relation, ['bryan', '6']),
          Row.new(relation, ['emilio', '42'])
        ]
      end
    end
  end
end