aboutsummaryrefslogtreecommitdiffstats
path: root/spec/relations/range_relation_spec.rb
blob: ea3901e3fdc414c3a274f081806853dc8d134c29 (plain) (blame)
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
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe RangeRelation do
  before do
    @relation1 = TableRelation.new(:foo)
    @relation2 = TableRelation.new(:bar)
    @range1 = 1..2
    @range2 = 4..9
  end
  
  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 do
          column :foo, :name
          column :foo, :id
        end
        from :foo
        limit range_size
        offset range_start
      end.to_s
    end
  end
  
end