aboutsummaryrefslogtreecommitdiffstats
path: root/spec/relations/join_operation_spec.rb
blob: db30198f6ec3b5181a740ec1f09977255f464585 (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 'between two relations' do
  before do
    @relation1 = TableRelation.new(:foo)
    @relation2 = TableRelation.new(:bar)
  end
  
  describe '==' do
    it "obtains if the relations of both joins are identical" do
      JoinOperation.new(@relation1, @relation2).should == JoinOperation.new(@relation1, @relation2)
      JoinOperation.new(@relation1, @relation2).should_not == JoinOperation.new(@relation1, @relation1)
    end
  
    it "is commutative on the relations" do
      JoinOperation.new(@relation1, @relation2).should == JoinOperation.new(@relation2, @relation1)
    end
  end

  describe '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 join relation of the appropriate type" do
      @join_operation.on(@predicate).should == JoinRelation.new(@relation1, @relation2, @predicate)
    end
  end
end