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

module Arel
  describe Binary do
    before do
      @relation = Table.new(:users)
      @attribute1 = @relation[:id]
      @attribute2 = @relation[:name]
      class ConcreteBinary < Binary
      end
    end

    describe '#bind' do
      before do
        @another_relation = @relation.alias
      end

      describe 'when both operands are attributes' do
        it "manufactures an expression with the attributes bound to the relation" do
          ConcreteBinary.new(@attribute1, @attribute2).bind(@another_relation). \
            should == ConcreteBinary.new(@another_relation[@attribute1], @another_relation[@attribute2])
        end
      end

      describe 'when an operand is a value' do
        it "manufactures an expression with unmodified values" do
          ConcreteBinary.new(@attribute1, "asdf").bind(@another_relation). \
            should == ConcreteBinary.new(@attribute1.find_correlate_in(@another_relation), "asdf".find_correlate_in(@another_relation))
        end
      end
    end
  end
end