aboutsummaryrefslogtreecommitdiffstats
path: root/spec/relations/relation_spec.rb
blob: d029827f216fd70f1668acadcc9f357cf0810984 (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

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 'joins' do
    describe '<=>' do
      it "manufactures an inner join operation between those two relations" do
        (@relation1 <=> @relation2).should == InnerJoinOperation.new(@relation1, @relation2)
      end
    end
    
    describe '<<' do
      it "manufactures a left outer join operation between those two relations" do
        (@relation1 << @relation2).should == LeftOuterJoinOperation.new(@relation1, @relation2)
      end      
    end
  end
  
  describe '[]' 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
  end
  
  describe '#include?' do
    it "manufactures an inclusion predicate" do
      @relation1.include?(@attribute1).should == RelationInclusionPredicate.new(@attribute1, @relation1)
    end
  end
  
  describe '#project' do
    it "collapses identical projections" do
      pending
    end
    
    it "manufactures a projection relation" do
      @relation1.project(@attribute1, @attribute2).should == ProjectionRelation.new(@relation1, @attribute1, @attribute2)
    end
  end
  
  describe '#rename' do
    it "manufactures a rename relation" do
      @relation1.rename(@attribute1, :foo).should == RenameRelation.new(@relation1, @attribute1 => :foo)
    end
  end
  
  describe '#select' do
    before do
      @predicate = EqualityPredicate.new(@attribute1, @attribute2)
    end
    
    it "manufactures a selection relation" do
      @relation1.select(@attribute1, @attribute2).should == SelectionRelation.new(@relation1, @attribute1, @attribute2)
    end
  end
  
  describe 'order' do
    it "manufactures an order relation" do
      @relation1.order(@attribute1, @attribute2).should == OrderRelation.new(@relation1, @attribute1, @attribute2)
    end
  end
end