aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/algebra/unit/relations/join_spec.rb
blob: f5a8bd32aa4af94813fe5e81a22378dbe63fd34f (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
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', 'spec_helper')

module Arel
  describe Join do
    before do
      @relation1 = Table.new(:users)
      @relation2 = Table.new(:photos)
      @predicate = @relation1[:id].eq(@relation2[:user_id])
    end

    describe 'hashing' do
      it 'implements hash equality' do
        InnerJoin.new(@relation1, @relation2, @predicate) \
          .should hash_the_same_as(InnerJoin.new(@relation1, @relation2, @predicate))
      end
    end

    describe '#attributes' do
      it 'combines the attributes of the two relations' do
        join = InnerJoin.new(@relation1, @relation2, @predicate)
        join.attributes.should ==
          (@relation1.attributes + @relation2.attributes).collect { |a| a.bind(join) }
      end
    end
  end
end