This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
/
collection_spec.rb
106 lines (81 loc) · 2.28 KB
/
collection_spec.rb
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
require 'spec_helper'
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
describe DataMapper::Collection do
it_should_behave_like 'It Has Setup Resources'
before :all do
@dragons = Dragon.all
@countries = Country.all
end
it_should_behave_like 'An Aggregatable Class'
describe 'ignore invalid query' do
before :all do
@dragons = @dragons.all(:id => [])
end
[ :size, :count ].each do |method|
describe "##{method}" do
it 'should return 0' do
@dragons.send(method).should == 0
end
end
end
describe '#min' do
it 'should return nil' do
@dragons.min(:id).should == nil
end
end
describe '#max' do
it 'should return nil' do
@dragons.max(:id).should == nil
end
end
describe '#avg' do
it 'should return nil' do
@dragons.avg(:id).should == nil
end
end
describe '#sum' do
it 'should return nil' do
@dragons.sum(:id).should == nil
end
end
describe '#aggregate' do
it 'should return nil' do
@dragons.aggregate(:id).should == []
end
end
end
describe 'with collections created with Set operations' do
before do
@collection = @dragons.all(:name => 'George') | @dragons.all(:name => 'Puff')
end
describe '#size' do
subject { @collection.size }
it { should == 2 }
end
describe '#count' do
subject { @collection.count }
it { should == 2 }
end
describe '#min' do
subject { @collection.min(:toes_on_claw) }
it { should == 3 }
end
describe '#max' do
subject { @collection.max(:toes_on_claw) }
it { should == 4 }
end
describe '#avg' do
subject { @collection.avg(:toes_on_claw) }
it { should == 3.5 }
end
describe '#sum' do
subject { @collection.sum(:toes_on_claw) }
it { should == 7 }
end
describe '#aggregate' do
subject { @collection.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum)}
it { should == [ 2, 2, 3, 4, 3.5, 7 ] }
end
end
end
end