aboutsummaryrefslogtreecommitdiffstats
path: root/spec/arel/engines/memory/unit/relations/array_spec.rb
blob: 22cddf7156341f7ae57b68f0ba4b9fe40e0d3ee3 (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..', 'spec_helper')

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

    describe '#attributes' do
      it 'manufactures attributes corresponding to the names given on construction' do
        @relation.attributes.should == [
          Attribute.new(@relation, :id),
          Attribute.new(@relation, :name)
        ]
      end
    end

    describe '#call' do
      it "manufactures an array of hashes of attributes to values" do
        @relation.call.should == [
          Row.new(@relation, [1, 'duck']),
          Row.new(@relation, [2, 'duck']),
          Row.new(@relation, [3, 'goose'])
        ]
      end
      
      describe 'where' do
        xit '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
        
        it 'filters the 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
      
      describe 'group' do
        xit 'sorts the relation with the provided ordering' do
        end
      end
      
      describe 'order' do
        it 'sorts the relation with the provided ordering' do
          @relation                     \
            .order(@relation[:id].desc) \
          .let do |relation|
            relation.call.should == [
              Row.new(relation, [3, 'goose']),
              Row.new(relation, [2, 'duck']),
              Row.new(relation, [1, 'duck'])
            ]
          end
        end
      end
      
      describe 'project' do
        it 'projects' do
          @relation                   \
            .project(@relation[:id])  \
          .let do |relation|
            relation.call.should == [
              Row.new(relation, [1]),
              Row.new(relation, [2]),
              Row.new(relation, [3])
            ]
          end
        end
      end
      
      describe 'skip' do
        it 'slices' do
          @relation   \
            .skip(1)  \
          .let do |relation|
            relation.call.should == [
              Row.new(relation, [2, 'duck']),
              Row.new(relation, [3, 'goose']),
            ]
          end
        end
      end
      
      describe 'take' do
        it 'dices' do
          @relation   \
            .take(2)  \
          .let do |relation|
            relation.call.should == [
              Row.new(relation, [1, 'duck']),
              Row.new(relation, [2, 'duck']),
            ]
          end
        end
      end
      
      describe 'join' do
      end
    end
  end
end