提交 09a58470 编写于 作者: A Aaron Patterson

removing test code from implementation

上级 53db9d80
......@@ -7,13 +7,6 @@ def initialize relation, tuple
@tuple = tuple
end
def == other
super ||
Row === other &&
relation == other.relation &&
tuple == other.tuple
end
def [](attribute)
attribute.type_cast(tuple[relation.position_of(attribute)])
end
......
......@@ -25,10 +25,15 @@ module Arel
.on(@users[:id].eq(@photos[:user_id])) \
.project(@users[:name], @photos[:camera_id]) \
.tap do |relation|
relation.call.should == [
Row.new(relation, ['bryan', @adapter_returns_integer ? 6 : '6']),
Row.new(relation, ['emilio', @adapter_returns_integer ? 42 : '42'])
]
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
......@@ -40,10 +45,15 @@ module Arel
.on(@users[:id].eq(@photos[:user_id])) \
.project(@users[:name], @photos[:camera_id]) \
.tap do |relation|
relation.call.should == [
Row.new(relation, ['bryan', @adapter_returns_integer ? 6 : '6']),
Row.new(relation, ['emilio', @adapter_returns_integer ? 42 : '42'])
]
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
......
......@@ -21,11 +21,12 @@ module Arel
describe '#call' do
it "manufactures an array of hashes of attributes to values" do
@relation.call.should == [
Row.new(@relation, [1, 'duck']),
Row.new(@relation, [2, 'duck']),
Row.new(@relation, [3, 'goose'])
]
rows = @relation.call
rows.length.should == 3
@relation.array.zip(rows).each do |tuple, row|
row.relation.should == @relation
row.tuple.should == tuple
end
end
end
end
......
......@@ -18,11 +18,12 @@ module Arel
.join(@relation2) \
.on(@relation1[:id].eq(@relation2[:id])) \
.tap 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'])
]
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
......
......@@ -15,11 +15,12 @@ module Arel
@relation \
.order(@relation[:id].desc) \
.tap do |relation|
relation.call.should == [
Row.new(relation, [3, 'goose']),
Row.new(relation, [2, 'duck' ]),
Row.new(relation, [1, 'duck' ])
]
rows = relation.call
rows.length.should == 3
@relation.array.reverse.zip(rows) do |tuple, row|
row.relation.should == relation
row.tuple.should == tuple
end
end
end
end
......
......@@ -15,11 +15,11 @@ module Arel
@relation \
.project(@relation[:id]) \
.tap do |relation|
relation.call.should == [
Row.new(relation, [1]),
Row.new(relation, [2]),
Row.new(relation, [3])
]
rows = relation.call
@relation.array.zip(rows) do |tuple, row|
row.relation.should == relation
row.tuple.should == [tuple.first]
end
end
end
end
......
......@@ -15,10 +15,15 @@ module Arel
@relation \
.skip(1) \
.tap do |relation|
relation.call.should == [
Row.new(relation, [2, 'duck']),
Row.new(relation, [3, 'goose']),
]
rows = relation.call
rows.length.should == 2
one, two = *rows
one.relation.should == relation
one.tuple.should == [2, 'duck']
two.relation.should == relation
two.tuple.should == [3, 'goose']
end
end
end
......
......@@ -15,10 +15,12 @@ module Arel
@relation \
.take(2) \
.tap do |relation|
relation.call.should == [
Row.new(relation, [1, 'duck']),
Row.new(relation, [2, 'duck']),
]
rows = relation.call
rows.length.should == 2
rows.each_with_index do |row, i|
row.relation.should == relation
row.tuple.should == [i + 1, 'duck']
end
end
end
end
......
......@@ -15,10 +15,12 @@ module Arel
@relation \
.where(@relation[:id].lt(3)) \
.tap do |relation|
relation.call.should == [
Row.new(relation, [1, 'duck']),
Row.new(relation, [2, 'duck']),
]
rows = relation.call
rows.length.should == 2
rows.each_with_index do |row, i|
row.relation.should == relation
row.tuple.should == [i + 1, 'duck']
end
end
end
......@@ -28,9 +30,11 @@ module Arel
.where(@relation[:id].gt(1)) \
.where(@relation[:id].lt(3)) \
.tap do |relation|
relation.call.should == [
Row.new(relation, [2, 'duck'])
]
rows = relation.call
rows.length.should == 1
row = rows.first
row.relation.should == relation
row.tuple.should == [2, 'duck']
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册