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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
require 'spec_helper'
module Arel
describe Join do
before do
@users = Array.new([
[1, 'bryan' ],
[2, 'emilio' ],
[3, 'nick']
], [[:id, Attributes::Integer], [:name, Attributes::String]])
@photos = Table.new(:photos)
@photos.delete
@photos.insert(@photos[:id] => 1, @photos[:user_id] => 1, @photos[:camera_id] => 6)
@photos.insert(@photos[:id] => 2, @photos[:user_id] => 2, @photos[:camera_id] => 42)
# Oracle adapter returns database integers as Ruby integers and not strings
# So does the FFI sqlite library
db_int_return = @photos.project(@photos[:camera_id]).first.tuple.first
@adapter_returns_integer = db_int_return.is_a?(String) ? false : true
end
describe 'when the in memory relation is on the left' do
it 'joins across engines' do
@users \
.join(@photos) \
.on(@users[:id].eq(@photos[:user_id])) \
.project(@users[:name], @photos[:camera_id]) \
.tap do |relation|
rows = relation.call
rows.length.should == 2
[
['bryan', @adapter_returns_integer ? 6 : '6'],
['emilio', @adapter_returns_integer ? 42 : '42']
].zip(rows).each do |tuple, row|
row.relation.should == relation
row.tuple.should == tuple
end
end
end
end
describe 'when the in memory relation is on the right' do
it 'joins across engines' do
@photos \
.join(@users) \
.on(@users[:id].eq(@photos[:user_id])) \
.project(@users[:name], @photos[:camera_id]) \
.tap do |relation|
rows = relation.call
rows.length.should == 2
[
['bryan', @adapter_returns_integer ? 6 : '6'],
['emilio', @adapter_returns_integer ? 42 : '42']
].zip(rows).each do |tuple, row|
row.relation.should == relation
row.tuple.should == tuple
end
end
end
end
end
end
|