1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/spec/relations/relation_spec.rb

74 lines
2.3 KiB
Ruby
Raw Normal View History

2007-12-30 14:35:44 -05:00
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
describe Relation do
before do
@relation1 = TableRelation.new(:foo)
@relation2 = TableRelation.new(:bar)
2007-12-30 16:48:13 -05:00
@attribute1 = Attribute.new(@relation1, :id)
@attribute2 = Attribute.new(@relation1, :name)
2007-12-30 14:35:44 -05:00
end
2007-12-30 16:48:13 -05:00
describe Relation, 'joins' do
describe Relation, '<=>' do
it "manufactures an inner join operation between those two relations" do
(@relation1 <=> @relation2).should == InnerJoinOperation.new(@relation1, @relation2)
end
end
describe Relation, '<<' do
it "manufactures a left outer join operation between those two relations" do
(@relation1 << @relation2).should == LeftOuterJoinOperation.new(@relation1, @relation2)
end
2007-12-30 14:35:44 -05:00
end
end
describe Relation, '[]' do
2007-12-30 16:48:13 -05:00
it "manufactures an attribute when given a symbol" do
2007-12-30 14:35:44 -05:00
@relation1[:id].should be_eql(Attribute.new(@relation1, :id))
end
2007-12-30 16:48:13 -05:00
it "manufactures a range relation when given a range" do
@relation1[1..2].should == RangeRelation.new(@relation1, 1..2)
end
2007-12-30 14:35:44 -05:00
it "raises an error if the named attribute is not part of the relation" do
2007-12-30 16:22:31 -05:00
pending
2007-12-30 14:35:44 -05:00
end
end
2007-12-30 16:22:31 -05:00
describe Relation, '#include?' do
2007-12-30 14:35:44 -05:00
it "manufactures an inclusion predicate" do
2007-12-30 16:48:13 -05:00
@relation1.include?(@attribute1).should == RelationInclusionPredicate.new(@attribute1, @relation1)
2007-12-30 14:35:44 -05:00
end
end
2007-12-30 16:22:31 -05:00
describe Relation, '#project' do
2007-12-30 14:35:44 -05:00
it "only allows projecting attributes in the relation" do
2007-12-30 16:22:31 -05:00
pending
2007-12-30 14:35:44 -05:00
end
it "collapses identical projections" do
2007-12-30 16:22:31 -05:00
pending
end
2007-12-30 16:48:13 -05:00
it "manufactures a projection relation" do
@relation1.project(@attribute1, @attribute2).should == ProjectionRelation.new(@relation1, @attribute1, @attribute2)
2007-12-30 14:35:44 -05:00
end
end
2007-12-30 16:22:31 -05:00
describe Relation, '#select' do
before do
2007-12-30 16:48:13 -05:00
@predicate = EqualityPredicate.new(@attribute1, @attribute2)
2007-12-30 16:22:31 -05:00
end
2007-12-30 16:48:13 -05:00
it "manufactures a selection relation" do
@relation1.select(@attribute1, @attribute2).should == SelectionRelation.new(@relation1, @attribute1, @attribute2)
2007-12-30 16:22:31 -05:00
end
2007-12-30 16:48:13 -05:00
end
describe Relation, 'order' do
it "manufactures an order relation" do
@relation1.order(@attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
end
end
2007-12-30 14:35:44 -05:00
end