aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/engines/memory/unit/relations/where_spec.rb
blob: 1d2c2eb39c66686fe700ff71b7f288ad8434a8ec (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
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')

module Arel
  describe Where do
    before do
      @relation = Array.new([
        [1, 'duck' ],
        [2, 'duck' ],
        [3, 'goose']
      ], [:id, :name])
    end

    describe '#call' do
      it 'filters the relation with the provided predicate' do
        @relation                       \
          .where(@relation[:id].lt(3))  \
        .let do |relation|
          relation.call.should == [
            Row.new(relation, [1, 'duck']),
            Row.new(relation, [2, 'duck']),
          ]
        end
      end

      describe 'when filtering a where relation' do
        it 'further filters the already-filtered relation with the provided predicate' do
          @relation                       \
            .where(@relation[:id].gt(1))  \
            .where(@relation[:id].lt(3))  \
          .let do |relation|
            relation.call.should == [
              Row.new(relation, [2, 'duck'])
            ]
          end
        end
      end
    end
  end
end