aboutsummaryrefslogtreecommitdiffstats
path: root/spec/relations
diff options
context:
space:
mode:
authorNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 13:48:13 -0800
committerNick Kallen <nkallen@nick-kallens-computer-2.local>2007-12-30 13:48:13 -0800
commit63b9c6a41f7ab92a16362a50b60bcea7e20cb427 (patch)
treeca3d84fe2b26d906035fb796e811b364a4cb5c0d /spec/relations
parentf9cc8bba39b1deb6b3f70cecb96beaf988054915 (diff)
downloadrails-63b9c6a41f7ab92a16362a50b60bcea7e20cb427.tar.gz
rails-63b9c6a41f7ab92a16362a50b60bcea7e20cb427.tar.bz2
rails-63b9c6a41f7ab92a16362a50b60bcea7e20cb427.zip
joins
Diffstat (limited to 'spec/relations')
-rw-r--r--spec/relations/join_operation_spec.rb10
-rw-r--r--spec/relations/relation_spec.rb51
2 files changed, 39 insertions, 22 deletions
diff --git a/spec/relations/join_operation_spec.rb b/spec/relations/join_operation_spec.rb
index 13e50e057e..d75d2d5c93 100644
--- a/spec/relations/join_operation_spec.rb
+++ b/spec/relations/join_operation_spec.rb
@@ -20,10 +20,16 @@ describe JoinOperation, 'between two relations' do
describe JoinOperation, 'on' do
before do
@predicate = Predicate.new
+ @join_operation = JoinOperation.new(@relation1, @relation2)
+ class << @join_operation
+ def relation_class
+ JoinRelation
+ end
+ end
end
- it "manufactures a JoinRelation" do
- JoinOperation.new(@relation1, @relation2).on(@predicate).should == JoinRelation.new(@relation1, @relation2, @predicate)
+ it "manufactures a join relation of the appropriate type" do
+ @join_operation.on(@predicate).should == JoinRelation.new(@relation1, @relation2, @predicate)
end
end
end \ No newline at end of file
diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb
index 7434bd563b..6c2c2b8611 100644
--- a/spec/relations/relation_spec.rb
+++ b/spec/relations/relation_spec.rb
@@ -4,40 +4,45 @@ describe Relation do
before do
@relation1 = TableRelation.new(:foo)
@relation2 = TableRelation.new(:bar)
+ @attribute1 = Attribute.new(@relation1, :id)
+ @attribute2 = Attribute.new(@relation1, :name)
end
- describe Relation, '*' do
- it "manufactures a JoinOperation between those two relations" do
- (@relation1 * @relation2).should == JoinOperation.new(@relation1, @relation2)
+ 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
end
end
describe Relation, '[]' do
- it "manufactures a attribute" do
+ it "manufactures an attribute when given a symbol" do
@relation1[:id].should be_eql(Attribute.new(@relation1, :id))
end
+ it "manufactures a range relation when given a range" do
+ @relation1[1..2].should == RangeRelation.new(@relation1, 1..2)
+ end
+
it "raises an error if the named attribute is not part of the relation" do
pending
end
end
describe Relation, '#include?' do
- before do
- @attribute = Attribute.new(@relation1, :id)
- end
-
it "manufactures an inclusion predicate" do
- @relation1.include?(@attribute).should == RelationInclusionPredicate.new(@attribute, @relation1)
+ @relation1.include?(@attribute1).should == RelationInclusionPredicate.new(@attribute1, @relation1)
end
end
describe Relation, '#project' do
- before do
- @attribute1 = Attribute.new(@relation1, :id)
- @attribute2 = Attribute.new(@relation1, :name)
- end
-
it "only allows projecting attributes in the relation" do
pending
end
@@ -46,18 +51,24 @@ describe Relation do
pending
end
- it "manufactures a projected relation" do
- @relation1.project(@attribute1, @attribute2).should == ProjectedRelation(@relation1, @attribute1, @attribute2)
+ it "manufactures a projection relation" do
+ @relation1.project(@attribute1, @attribute2).should == ProjectionRelation.new(@relation1, @attribute1, @attribute2)
end
end
describe Relation, '#select' do
before do
- @predicate = EqualityPredicate.new()
+ @predicate = EqualityPredicate.new(@attribute1, @attribute2)
end
- it "manufactures a selected relation" do
- @relation1.select(@attribute1, @attribute2).should == SelectedRelation(@relation1, @attribute1, @attribute2)
+ it "manufactures a selection relation" do
+ @relation1.select(@attribute1, @attribute2).should == SelectionRelation.new(@relation1, @attribute1, @attribute2)
end
- end
+ end
+
+ describe Relation, 'order' do
+ it "manufactures an order relation" do
+ @relation1.order(@attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
+ end
+ end
end \ No newline at end of file