diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/relations/order_relation_spec.rb | 13 | ||||
-rw-r--r-- | spec/relations/projection_relation_spec.rb | 11 | ||||
-rw-r--r-- | spec/relations/range_relation_spec.rb | 18 |
3 files changed, 38 insertions, 4 deletions
diff --git a/spec/relations/order_relation_spec.rb b/spec/relations/order_relation_spec.rb index 362544d0d1..4f7a18fc8e 100644 --- a/spec/relations/order_relation_spec.rb +++ b/spec/relations/order_relation_spec.rb @@ -8,11 +8,22 @@ describe OrderRelation do @attribute2 = @relation2[:bar] end - describe OrderRelation, '==' do + describe '==' do it "obtains if the relation and attributes are identical" do OrderRelation.new(@relation1, @attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2) OrderRelation.new(@relation1, @attribute1).should_not == OrderRelation.new(@relation2, @attribute1) OrderRelation.new(@relation1, @attribute1, @attribute2).should_not == OrderRelation.new(@relation1, @attribute2, @attribute1) end end + + describe '#to_s' do + it "manufactures sql with an order clause" do + OrderRelation.new(@relation1, @attribute1).to_sql.should == SelectBuilder.new do + select :* + from :foo + order_by 'foo.foo' + end + end + end + end
\ No newline at end of file diff --git a/spec/relations/projection_relation_spec.rb b/spec/relations/projection_relation_spec.rb index f802a2e293..ba5620dcde 100644 --- a/spec/relations/projection_relation_spec.rb +++ b/spec/relations/projection_relation_spec.rb @@ -8,11 +8,20 @@ describe ProjectionRelation do @attribute2 = @relation2[:bar] end - describe ProjectionRelation, '==' do + describe '==' do it "obtains if the relations and attributes are identical" do ProjectionRelation.new(@relation1, @attribute1, @attribute2).should == ProjectionRelation.new(@relation1, @attribute1, @attribute2) ProjectionRelation.new(@relation1, @attribute1).should_not == ProjectionRelation.new(@relation2, @attribute1) ProjectionRelation.new(@relation1, @attribute1).should_not == ProjectionRelation.new(@relation1, @attribute2) end end + + describe '#to_sql' do + it "manufactures sql with a limited select clause" do + ProjectionRelation.new(@relation1, @attribute1).to_sql.should == SelectBuilder.new do + select 'foo.foo' + from :foo + end + end + end end
\ No newline at end of file diff --git a/spec/relations/range_relation_spec.rb b/spec/relations/range_relation_spec.rb index 2a1cd1d070..fc7094c873 100644 --- a/spec/relations/range_relation_spec.rb +++ b/spec/relations/range_relation_spec.rb @@ -5,14 +5,28 @@ describe RangeRelation do @relation1 = TableRelation.new(:foo) @relation2 = TableRelation.new(:bar) @range1 = 1..2 - @range2 = Time.now..2.days.from_now + @range2 = 4..9 end - describe RangeRelation, '==' do + describe '==' do it "obtains if the relation and range are identical" do RangeRelation.new(@relation1, @range1).should == RangeRelation.new(@relation1, @range1) RangeRelation.new(@relation1, @range1).should_not == RangeRelation.new(@relation2, @range1) RangeRelation.new(@relation1, @range1).should_not == RangeRelation.new(@relation1, @range2) end end + + describe '#to_sql' do + it "manufactures sql with limit and offset" do + range_size = @range2.last - @range2.first + 1 + range_start = @range2.first + RangeRelation.new(@relation1, @range2).to_sql.to_s.should == SelectBuilder.new do + select :* + from :foo + limit range_size + offset range_start + end.to_s + end + end + end
\ No newline at end of file |