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

describe ProjectionRelation do
  before do
    @relation1 = TableRelation.new(:foo)
    @relation2 = TableRelation.new(:bar)
    @attribute1 = @relation1[:id]
    @attribute2 = @relation2[:id]
  end
  
  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.to_s.should == SelectBuilder.new do
        select do
          column :foo, :id
        end
        from :foo
      end.to_s
    end
  end
end