dm-aggregates 1.1.0 → 1.2.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +8 -8
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/dm-aggregates.gemspec +22 -31
- data/spec/public/collection_spec.rb +45 -61
- data/spec/public/model_spec.rb +3 -6
- data/spec/public/shared/aggregate_shared_spec.rb +171 -152
- metadata +65 -36
data/Gemfile
CHANGED
@@ -5,26 +5,26 @@ source 'http://rubygems.org'
|
|
5
5
|
SOURCE = ENV.fetch('SOURCE', :git).to_sym
|
6
6
|
REPO_POSTFIX = SOURCE == :path ? '' : '.git'
|
7
7
|
DATAMAPPER = SOURCE == :path ? Pathname(__FILE__).dirname.parent : 'http://github.com/datamapper'
|
8
|
-
DM_VERSION = '~> 1.
|
9
|
-
DO_VERSION = '~> 0.10.
|
8
|
+
DM_VERSION = '~> 1.2.0.rc1'
|
9
|
+
DO_VERSION = '~> 0.10.6'
|
10
10
|
DM_DO_ADAPTERS = %w[ sqlite postgres mysql oracle sqlserver ]
|
11
11
|
|
12
12
|
gem 'dm-core', DM_VERSION, SOURCE => "#{DATAMAPPER}/dm-core#{REPO_POSTFIX}"
|
13
13
|
|
14
14
|
group :development do
|
15
15
|
|
16
|
-
gem 'jeweler', '~> 1.
|
17
|
-
gem 'rake', '~> 0.
|
18
|
-
gem 'rspec', '~> 1.3.
|
16
|
+
gem 'jeweler', '~> 1.6.4'
|
17
|
+
gem 'rake', '~> 0.9.2'
|
18
|
+
gem 'rspec', '~> 1.3.2'
|
19
19
|
|
20
20
|
end
|
21
21
|
|
22
22
|
platforms :mri_18 do
|
23
23
|
group :quality do
|
24
24
|
|
25
|
-
gem 'rcov', '~> 0.9.
|
26
|
-
gem 'yard', '~> 0.
|
27
|
-
gem 'yardstick', '~> 0.
|
25
|
+
gem 'rcov', '~> 0.9.10'
|
26
|
+
gem 'yard', '~> 0.7.2'
|
27
|
+
gem 'yardstick', '~> 0.4'
|
28
28
|
|
29
29
|
end
|
30
30
|
end
|
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0.rc1
|
data/dm-aggregates.gemspec
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
|
-
s.name =
|
8
|
-
s.version = "1.
|
7
|
+
s.name = "dm-aggregates"
|
8
|
+
s.version = "1.2.0.rc1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Foy Savas"]
|
12
|
-
s.date =
|
13
|
-
s.description =
|
14
|
-
s.email =
|
12
|
+
s.date = "2011-09-09"
|
13
|
+
s.description = "DataMapper plugin providing support for aggregates on collections"
|
14
|
+
s.email = "foysavas [a] gmail [d] com"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE",
|
17
17
|
"README.rdoc"
|
@@ -46,40 +46,31 @@ Gem::Specification.new do |s|
|
|
46
46
|
"tasks/yard.rake",
|
47
47
|
"tasks/yardstick.rake"
|
48
48
|
]
|
49
|
-
s.homepage =
|
49
|
+
s.homepage = "http://github.com/datamapper/dm-aggregates"
|
50
50
|
s.require_paths = ["lib"]
|
51
|
-
s.rubyforge_project =
|
52
|
-
s.rubygems_version =
|
53
|
-
s.summary =
|
54
|
-
s.test_files = [
|
55
|
-
"spec/isolated/require_after_setup_spec.rb",
|
56
|
-
"spec/isolated/require_before_setup_spec.rb",
|
57
|
-
"spec/isolated/require_spec.rb",
|
58
|
-
"spec/public/collection_spec.rb",
|
59
|
-
"spec/public/model_spec.rb",
|
60
|
-
"spec/public/shared/aggregate_shared_spec.rb",
|
61
|
-
"spec/spec_helper.rb"
|
62
|
-
]
|
51
|
+
s.rubyforge_project = "datamapper"
|
52
|
+
s.rubygems_version = "1.8.10"
|
53
|
+
s.summary = "DataMapper plugin providing support for aggregates on collections"
|
63
54
|
|
64
55
|
if s.respond_to? :specification_version then
|
65
56
|
s.specification_version = 3
|
66
57
|
|
67
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
68
|
-
s.add_runtime_dependency(%q<dm-core>, ["~> 1.
|
69
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.
|
70
|
-
s.add_development_dependency(%q<rake>, ["~> 0.
|
71
|
-
s.add_development_dependency(%q<rspec>, ["~> 1.3.
|
59
|
+
s.add_runtime_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
|
60
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
61
|
+
s.add_development_dependency(%q<rake>, ["~> 0.9.2"])
|
62
|
+
s.add_development_dependency(%q<rspec>, ["~> 1.3.2"])
|
72
63
|
else
|
73
|
-
s.add_dependency(%q<dm-core>, ["~> 1.
|
74
|
-
s.add_dependency(%q<jeweler>, ["~> 1.
|
75
|
-
s.add_dependency(%q<rake>, ["~> 0.
|
76
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.
|
64
|
+
s.add_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
|
65
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
66
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
67
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.2"])
|
77
68
|
end
|
78
69
|
else
|
79
|
-
s.add_dependency(%q<dm-core>, ["~> 1.
|
80
|
-
s.add_dependency(%q<jeweler>, ["~> 1.
|
81
|
-
s.add_dependency(%q<rake>, ["~> 0.
|
82
|
-
s.add_dependency(%q<rspec>, ["~> 1.3.
|
70
|
+
s.add_dependency(%q<dm-core>, ["~> 1.2.0.rc1"])
|
71
|
+
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
72
|
+
s.add_dependency(%q<rake>, ["~> 0.9.2"])
|
73
|
+
s.add_dependency(%q<rspec>, ["~> 1.3.2"])
|
83
74
|
end
|
84
75
|
end
|
85
76
|
|
@@ -1,141 +1,125 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Collection do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
@dragons = Dragon.all
|
7
|
-
@countries = Country.all
|
8
|
-
end
|
9
|
-
|
10
4
|
supported_by :sqlite, :mysql, :postgres do
|
5
|
+
let(:dragons) { Dragon.all }
|
6
|
+
let(:countries) { Country.all }
|
11
7
|
|
12
8
|
it_should_behave_like 'It Has Setup Resources'
|
13
9
|
it_should_behave_like 'An Aggregatable Class'
|
14
10
|
|
15
11
|
describe 'ignore invalid query' do
|
16
|
-
|
17
|
-
@dragons = @dragons.all(:id => [])
|
18
|
-
end
|
12
|
+
let(:dragons) { Dragon.all.all(:id => []) }
|
19
13
|
|
20
14
|
[ :size, :count ].each do |method|
|
21
15
|
describe "##{method}" do
|
22
|
-
|
23
|
-
|
24
|
-
|
16
|
+
subject { dragons.send(method) }
|
17
|
+
|
18
|
+
it { should == 0 }
|
25
19
|
end
|
26
20
|
end
|
27
21
|
|
28
22
|
describe '#min' do
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
subject { dragons.min(:id) }
|
24
|
+
|
25
|
+
it { should be_nil }
|
32
26
|
end
|
33
27
|
|
34
28
|
describe '#max' do
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
subject { dragons.max(:id) }
|
30
|
+
|
31
|
+
it { should be_nil }
|
38
32
|
end
|
39
33
|
|
40
34
|
describe '#avg' do
|
41
|
-
|
42
|
-
|
43
|
-
|
35
|
+
subject { dragons.avg(:id) }
|
36
|
+
|
37
|
+
it { should be_nil }
|
44
38
|
end
|
45
39
|
|
46
40
|
describe '#sum' do
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
subject { dragons.sum(:id) }
|
42
|
+
|
43
|
+
it { should be_nil }
|
50
44
|
end
|
51
45
|
|
52
46
|
describe '#aggregate' do
|
53
|
-
|
54
|
-
|
55
|
-
|
47
|
+
subject { dragons.aggregate(:id) }
|
48
|
+
|
49
|
+
it { should == [] }
|
56
50
|
end
|
57
51
|
end
|
58
52
|
|
59
|
-
|
60
|
-
|
61
|
-
@collection = @dragons.all(:name => 'George') | @dragons.all(:name => 'Puff')
|
62
|
-
end
|
53
|
+
context 'with collections created with Set operations' do
|
54
|
+
let(:collection) { dragons.all(:name => 'George') | dragons.all(:name => 'Puff') }
|
63
55
|
|
64
56
|
describe '#size' do
|
65
|
-
subject {
|
57
|
+
subject { collection.size }
|
66
58
|
|
67
59
|
it { should == 2 }
|
68
60
|
end
|
69
61
|
|
70
62
|
describe '#count' do
|
71
|
-
subject {
|
63
|
+
subject { collection.count }
|
72
64
|
|
73
65
|
it { should == 2 }
|
74
66
|
end
|
75
67
|
|
76
68
|
describe '#min' do
|
77
|
-
subject {
|
69
|
+
subject { collection.min(:toes_on_claw) }
|
78
70
|
|
79
71
|
it { should == 3 }
|
80
72
|
end
|
81
73
|
|
82
74
|
describe '#max' do
|
83
|
-
subject {
|
75
|
+
subject { collection.max(:toes_on_claw) }
|
84
76
|
|
85
77
|
it { should == 4 }
|
86
78
|
end
|
87
79
|
|
88
80
|
describe '#avg' do
|
89
|
-
subject {
|
81
|
+
subject { collection.avg(:toes_on_claw) }
|
90
82
|
|
91
83
|
it { should == 3.5 }
|
92
84
|
end
|
93
85
|
|
94
86
|
describe '#sum' do
|
95
|
-
subject {
|
87
|
+
subject { collection.sum(:toes_on_claw) }
|
96
88
|
|
97
89
|
it { should == 7 }
|
98
90
|
end
|
99
91
|
|
100
92
|
describe '#aggregate' do
|
101
|
-
subject {
|
93
|
+
subject { collection.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum)}
|
102
94
|
|
103
95
|
it { should == [ 2, 2, 3, 4, 3.5, 7 ] }
|
104
96
|
end
|
105
97
|
end
|
106
98
|
|
107
|
-
|
99
|
+
context 'with a collection limited to 1 result' do
|
100
|
+
let(:dragons) { Dragon.all(:limit => 1) }
|
108
101
|
|
109
|
-
|
110
|
-
|
111
|
-
end
|
102
|
+
describe '#size' do
|
103
|
+
subject { dragons.size }
|
112
104
|
|
113
|
-
|
114
|
-
it 'should return 1' do
|
115
|
-
@dragons.size.should == 1
|
116
|
-
end
|
105
|
+
it { should == 1 }
|
117
106
|
end
|
118
107
|
|
119
|
-
describe
|
120
|
-
|
121
|
-
pending 'TODO: make count apply to the limited collection. Currently limit applies after the count' do
|
122
|
-
@dragons.count.should == 1
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
108
|
+
describe '#count' do
|
109
|
+
subject { dragons.count }
|
126
110
|
|
111
|
+
it { pending('TODO: make count apply to the limited collection. Currently limit applies after the count') { should == 1 } }
|
112
|
+
end
|
127
113
|
end
|
128
114
|
|
129
|
-
|
130
|
-
|
131
|
-
@dragons = Dragon.all(:order => [ :birth_at.desc ])
|
132
|
-
end
|
115
|
+
context 'with the order reversed by the grouping field' do
|
116
|
+
subject { dragons.aggregate(:birth_at, :all.count) }
|
133
117
|
|
134
|
-
|
135
|
-
|
118
|
+
let(:dragons) { Dragon.all(:order => [ :birth_at.desc ]) }
|
119
|
+
|
120
|
+
it 'displays the results in reverse order' do
|
121
|
+
should == Dragon.aggregate(:birth_at, :all.count).reverse
|
136
122
|
end
|
137
123
|
end
|
138
|
-
|
139
124
|
end
|
140
|
-
|
141
125
|
end
|
data/spec/public/model_spec.rb
CHANGED
@@ -1,13 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Model do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
@dragons = Dragon
|
7
|
-
@countries = Country
|
8
|
-
end
|
9
|
-
|
10
4
|
supported_by :sqlite, :mysql, :postgres do
|
5
|
+
let(:dragons) { Dragon }
|
6
|
+
let(:countries) { Country }
|
7
|
+
|
11
8
|
it_should_behave_like 'It Has Setup Resources'
|
12
9
|
it_should_behave_like 'An Aggregatable Class'
|
13
10
|
end
|
@@ -7,7 +7,6 @@ shared_examples_for 'It Has Setup Resources' do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
before :all do
|
10
|
-
|
11
10
|
DataMapper.auto_migrate!
|
12
11
|
|
13
12
|
@birth_at = DateTime.now
|
@@ -17,46 +16,66 @@ shared_examples_for 'It Has Setup Resources' do
|
|
17
16
|
@chuck = Knight.create(:name => 'Chuck')
|
18
17
|
@larry = Knight.create(:name => 'Larry')
|
19
18
|
|
20
|
-
Dragon.create(:name => 'George', :is_fire_breathing => false, :toes_on_claw => 3, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time, :knight => @chuck
|
21
|
-
Dragon.create(:name => 'Puff', :is_fire_breathing => true, :toes_on_claw => 4, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time, :knight => @larry
|
19
|
+
Dragon.create(:name => 'George', :is_fire_breathing => false, :toes_on_claw => 3, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time, :knight => @chuck)
|
20
|
+
Dragon.create(:name => 'Puff', :is_fire_breathing => true, :toes_on_claw => 4, :birth_at => @birth_at, :birth_on => @birth_on, :birth_time => @birth_time, :knight => @larry)
|
22
21
|
Dragon.create(:name => nil, :is_fire_breathing => true, :toes_on_claw => 5, :birth_at => nil, :birth_on => nil, :birth_time => nil)
|
23
22
|
|
24
|
-
gold_kilo_price
|
23
|
+
gold_kilo_price = 277738.70
|
25
24
|
@gold_tonne_price = gold_kilo_price * 10000
|
26
25
|
|
27
|
-
Country.create(
|
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
|
-
|
26
|
+
Country.create(
|
27
|
+
:name => 'China',
|
28
|
+
:population => 1330044605,
|
29
|
+
:birth_rate => 13.71,
|
30
|
+
:gold_reserve_tonnes => 600.0,
|
31
|
+
:gold_reserve_value => 600.0 * @gold_tonne_price # => 32150000
|
32
|
+
)
|
33
|
+
|
34
|
+
Country.create(
|
35
|
+
:name => 'United States',
|
36
|
+
:population => 303824646,
|
37
|
+
:birth_rate => 14.18,
|
38
|
+
:gold_reserve_tonnes => 8133.5,
|
39
|
+
:gold_reserve_value => 8133.5 * @gold_tonne_price
|
40
|
+
)
|
41
|
+
|
42
|
+
Country.create(
|
43
|
+
:name => 'Brazil',
|
44
|
+
:population => 191908598,
|
45
|
+
:birth_rate => 16.04,
|
46
|
+
:gold_reserve_tonnes => nil # example of no stats available
|
47
|
+
)
|
48
|
+
|
49
|
+
Country.create(
|
50
|
+
:name => 'Russia',
|
51
|
+
:population => 140702094,
|
52
|
+
:birth_rate => 11.03,
|
53
|
+
:gold_reserve_tonnes => 438.2,
|
54
|
+
:gold_reserve_value => 438.2 * @gold_tonne_price
|
55
|
+
)
|
56
|
+
|
57
|
+
Country.create(
|
58
|
+
:name => 'Japan',
|
59
|
+
:population => 127288419,
|
60
|
+
:birth_rate => 7.87,
|
61
|
+
:gold_reserve_tonnes => 765.2,
|
62
|
+
:gold_reserve_value => 765.2 * @gold_tonne_price
|
63
|
+
)
|
64
|
+
|
65
|
+
Country.create(
|
66
|
+
:name => 'Mexico',
|
67
|
+
:population => 109955400,
|
68
|
+
:birth_rate => 20.04,
|
69
|
+
:gold_reserve_tonnes => nil # example of no stats available
|
70
|
+
)
|
71
|
+
|
72
|
+
Country.create(
|
73
|
+
:name => 'Germany',
|
74
|
+
:population => 82369548,
|
75
|
+
:birth_rate => 8.18,
|
76
|
+
:gold_reserve_tonnes => 3417.4,
|
77
|
+
:gold_reserve_value => 3417.4 * @gold_tonne_price
|
78
|
+
)
|
60
79
|
|
61
80
|
@approx_by = 0.0001
|
62
81
|
end
|
@@ -70,234 +89,234 @@ shared_examples_for 'An Aggregatable Class' do
|
|
70
89
|
describe '#count' do
|
71
90
|
it_should_behave_like 'count with no arguments'
|
72
91
|
|
73
|
-
|
74
|
-
it '
|
75
|
-
|
92
|
+
context 'with a property name' do
|
93
|
+
it 'counts the results' do
|
94
|
+
dragons.count(:name).should == 2
|
76
95
|
end
|
77
96
|
|
78
|
-
it '
|
79
|
-
|
97
|
+
it 'counts the results with conditions having operators' do
|
98
|
+
dragons.count(:name, :toes_on_claw.gt => 3).should == 1
|
80
99
|
end
|
81
100
|
|
82
|
-
it '
|
101
|
+
it 'counts the results with raw conditions' do
|
83
102
|
statement = 'is_fire_breathing = ?'
|
84
|
-
|
85
|
-
|
103
|
+
dragons.count(:name, :conditions => [ statement, false ]).should == 1
|
104
|
+
dragons.count(:name, :conditions => [ statement, true ]).should == 1
|
86
105
|
end
|
87
106
|
end
|
88
107
|
end
|
89
108
|
|
90
109
|
describe '#min' do
|
91
|
-
|
92
|
-
it '
|
93
|
-
|
110
|
+
context 'with no arguments' do
|
111
|
+
it 'raises an error' do
|
112
|
+
expect { dragons.min }.to raise_error(ArgumentError)
|
94
113
|
end
|
95
114
|
end
|
96
115
|
|
97
|
-
|
98
|
-
it '
|
99
|
-
|
100
|
-
|
116
|
+
context 'with a property name' do
|
117
|
+
it 'provides the lowest value of an Integer property' do
|
118
|
+
dragons.min(:toes_on_claw).should == 3
|
119
|
+
countries.min(:population).should == 82369548
|
101
120
|
end
|
102
121
|
|
103
|
-
it '
|
104
|
-
|
105
|
-
|
106
|
-
|
122
|
+
it 'provides the lowest value of a Float property' do
|
123
|
+
countries.min(:birth_rate).should be_kind_of(Float)
|
124
|
+
countries.min(:birth_rate).should >= 7.87 - @approx_by # approx match
|
125
|
+
countries.min(:birth_rate).should <= 7.87 + @approx_by # approx match
|
107
126
|
end
|
108
127
|
|
109
|
-
it '
|
110
|
-
|
111
|
-
|
128
|
+
it 'provides the lowest value of a BigDecimal property' do
|
129
|
+
countries.min(:gold_reserve_value).should be_kind_of(BigDecimal)
|
130
|
+
countries.min(:gold_reserve_value).should == BigDecimal('1217050983400.0')
|
112
131
|
end
|
113
132
|
|
114
|
-
it '
|
133
|
+
it 'provides the lowest value of a DateTime property' do
|
115
134
|
pending_if 'TODO: returns incorrect value until DO handles TZs properly', @skip do
|
116
|
-
|
117
|
-
|
135
|
+
dragons.min(:birth_at).should be_kind_of(DateTime)
|
136
|
+
dragons.min(:birth_at).to_s.should == @birth_at.to_s
|
118
137
|
end
|
119
138
|
end
|
120
139
|
|
121
|
-
it '
|
122
|
-
|
123
|
-
|
140
|
+
it 'provides the lowest value of a Date property' do
|
141
|
+
dragons.min(:birth_on).should be_kind_of(Date)
|
142
|
+
dragons.min(:birth_on).should == @birth_on
|
124
143
|
end
|
125
144
|
|
126
|
-
it '
|
127
|
-
|
128
|
-
|
145
|
+
it 'provides the lowest value of a Time property' do
|
146
|
+
dragons.min(:birth_time).should be_kind_of(Time)
|
147
|
+
dragons.min(:birth_time).to_s.should == @birth_time.to_s
|
129
148
|
end
|
130
149
|
|
131
|
-
it '
|
132
|
-
|
133
|
-
|
150
|
+
it 'provides the lowest value when conditions provided' do
|
151
|
+
dragons.min(:toes_on_claw, :is_fire_breathing => true).should == 4
|
152
|
+
dragons.min(:toes_on_claw, :is_fire_breathing => false).should == 3
|
134
153
|
end
|
135
154
|
end
|
136
155
|
end
|
137
156
|
|
138
157
|
describe '#max' do
|
139
|
-
|
140
|
-
it '
|
141
|
-
|
158
|
+
context 'with no arguments' do
|
159
|
+
it 'raises an error' do
|
160
|
+
expect { dragons.max }.to raise_error(ArgumentError)
|
142
161
|
end
|
143
162
|
end
|
144
163
|
|
145
|
-
|
146
|
-
it '
|
147
|
-
|
148
|
-
|
164
|
+
context 'with a property name' do
|
165
|
+
it 'provides the highest value of an Integer property' do
|
166
|
+
dragons.max(:toes_on_claw).should == 5
|
167
|
+
countries.max(:population).should == 1330044605
|
149
168
|
end
|
150
169
|
|
151
|
-
it '
|
152
|
-
|
153
|
-
|
154
|
-
|
170
|
+
it 'provides the highest value of a Float property' do
|
171
|
+
countries.max(:birth_rate).should be_kind_of(Float)
|
172
|
+
countries.max(:birth_rate).should >= 20.04 - @approx_by # approx match
|
173
|
+
countries.max(:birth_rate).should <= 20.04 + @approx_by # approx match
|
155
174
|
end
|
156
175
|
|
157
|
-
it '
|
158
|
-
|
176
|
+
it 'provides the highest value of a BigDecimal property' do
|
177
|
+
countries.max(:gold_reserve_value).should == BigDecimal('22589877164500.0')
|
159
178
|
end
|
160
179
|
|
161
|
-
it '
|
180
|
+
it 'provides the highest value of a DateTime property' do
|
162
181
|
pending_if 'TODO: returns incorrect value until DO handles TZs properly', @skip do
|
163
|
-
|
164
|
-
|
182
|
+
dragons.min(:birth_at).should be_kind_of(DateTime)
|
183
|
+
dragons.min(:birth_at).to_s.should == @birth_at.to_s
|
165
184
|
end
|
166
185
|
end
|
167
186
|
|
168
|
-
it '
|
169
|
-
|
170
|
-
|
187
|
+
it 'provides the highest value of a Date property' do
|
188
|
+
dragons.min(:birth_on).should be_kind_of(Date)
|
189
|
+
dragons.min(:birth_on).should == @birth_on
|
171
190
|
end
|
172
191
|
|
173
|
-
it '
|
174
|
-
|
175
|
-
|
192
|
+
it 'provides the highest value of a Time property' do
|
193
|
+
dragons.min(:birth_time).should be_kind_of(Time)
|
194
|
+
dragons.min(:birth_time).to_s.should == @birth_time.to_s
|
176
195
|
end
|
177
196
|
|
178
|
-
it '
|
179
|
-
|
180
|
-
|
197
|
+
it 'provides the highest value when conditions provided' do
|
198
|
+
dragons.max(:toes_on_claw, :is_fire_breathing => true).should == 5
|
199
|
+
dragons.max(:toes_on_claw, :is_fire_breathing => false).should == 3
|
181
200
|
end
|
182
201
|
end
|
183
202
|
end
|
184
203
|
|
185
204
|
describe '#avg' do
|
186
|
-
|
187
|
-
it '
|
188
|
-
|
205
|
+
context 'with no arguments' do
|
206
|
+
it 'raises an error' do
|
207
|
+
expect { dragons.avg }.to raise_error(ArgumentError)
|
189
208
|
end
|
190
209
|
end
|
191
210
|
|
192
|
-
|
193
|
-
it '
|
194
|
-
|
195
|
-
|
211
|
+
context 'with a property name' do
|
212
|
+
it 'provides the average value of an Integer property' do
|
213
|
+
dragons.avg(:toes_on_claw).should be_kind_of(Float)
|
214
|
+
dragons.avg(:toes_on_claw).should == 4.0
|
196
215
|
end
|
197
216
|
|
198
|
-
it '
|
217
|
+
it 'provides the average value of a Float property' do
|
199
218
|
mean_birth_rate = (13.71 + 14.18 + 16.04 + 11.03 + 7.87 + 20.04 + 8.18) / 7
|
200
|
-
|
201
|
-
|
202
|
-
|
219
|
+
countries.avg(:birth_rate).should be_kind_of(Float)
|
220
|
+
countries.avg(:birth_rate).should >= mean_birth_rate - @approx_by # approx match
|
221
|
+
countries.avg(:birth_rate).should <= mean_birth_rate + @approx_by # approx match
|
203
222
|
end
|
204
223
|
|
205
|
-
it '
|
224
|
+
it 'provides the average value of a BigDecimal property' do
|
206
225
|
mean_gold_reserve_value = ((600.0 + 8133.50 + 438.20 + 765.20 + 3417.40) * @gold_tonne_price) / 5
|
207
|
-
|
208
|
-
|
226
|
+
countries.avg(:gold_reserve_value).should be_kind_of(BigDecimal)
|
227
|
+
countries.avg(:gold_reserve_value).should == BigDecimal(mean_gold_reserve_value.to_s)
|
209
228
|
end
|
210
229
|
|
211
|
-
it '
|
212
|
-
|
213
|
-
|
230
|
+
it 'provides the average value when conditions provided' do
|
231
|
+
dragons.avg(:toes_on_claw, :is_fire_breathing => true).should == 4.5
|
232
|
+
dragons.avg(:toes_on_claw, :is_fire_breathing => false).should == 3
|
214
233
|
end
|
215
234
|
end
|
216
235
|
end
|
217
236
|
|
218
237
|
describe '#sum' do
|
219
|
-
|
220
|
-
it '
|
221
|
-
|
238
|
+
context 'with no arguments' do
|
239
|
+
it 'raises an error' do
|
240
|
+
expect { dragons.sum }.to raise_error(ArgumentError)
|
222
241
|
end
|
223
242
|
end
|
224
243
|
|
225
|
-
|
226
|
-
it '
|
227
|
-
|
244
|
+
context 'with a property name' do
|
245
|
+
it 'provides the sum of values for an Integer property' do
|
246
|
+
dragons.sum(:toes_on_claw).should == 12
|
228
247
|
|
229
248
|
total_population = 1330044605 + 303824646 + 191908598 + 140702094 +
|
230
249
|
127288419 + 109955400 + 82369548
|
231
|
-
|
250
|
+
countries.sum(:population).should == total_population
|
232
251
|
end
|
233
252
|
|
234
|
-
it '
|
253
|
+
it 'provides the sum of values for a Float property' do
|
235
254
|
total_tonnes = 600.0 + 8133.5 + 438.2 + 765.2 + 3417.4
|
236
|
-
|
237
|
-
|
238
|
-
|
255
|
+
countries.sum(:gold_reserve_tonnes).should be_kind_of(Float)
|
256
|
+
countries.sum(:gold_reserve_tonnes).should >= total_tonnes - @approx_by # approx match
|
257
|
+
countries.sum(:gold_reserve_tonnes).should <= total_tonnes + @approx_by # approx match
|
239
258
|
end
|
240
259
|
|
241
|
-
it '
|
242
|
-
|
260
|
+
it 'provides the sum of values for a BigDecimal property' do
|
261
|
+
countries.sum(:gold_reserve_value).should == BigDecimal('37090059214100.0')
|
243
262
|
end
|
244
263
|
|
245
|
-
it '
|
246
|
-
|
247
|
-
|
264
|
+
it 'provides the average value when conditions provided' do
|
265
|
+
dragons.sum(:toes_on_claw, :is_fire_breathing => true).should == 9
|
266
|
+
dragons.sum(:toes_on_claw, :is_fire_breathing => false).should == 3
|
248
267
|
end
|
249
268
|
end
|
250
269
|
end
|
251
270
|
|
252
271
|
describe '#aggregate' do
|
253
|
-
|
254
|
-
it '
|
255
|
-
|
272
|
+
context 'with no arguments' do
|
273
|
+
it 'raises an error' do
|
274
|
+
expect { dragons.aggregate }.to raise_error(ArgumentError)
|
256
275
|
end
|
257
276
|
end
|
258
277
|
|
259
|
-
|
260
|
-
it '
|
261
|
-
results =
|
278
|
+
context 'with only aggregate fields specified' do
|
279
|
+
it 'provides aggregate results' do
|
280
|
+
results = dragons.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum)
|
262
281
|
results.should == [ 3, 2, 3, 5, 4.0, 12 ]
|
263
282
|
end
|
264
283
|
end
|
265
284
|
|
266
|
-
|
267
|
-
it '
|
268
|
-
results =
|
285
|
+
context 'with aggregate fields and a property to group by' do
|
286
|
+
it 'provides aggregate results' do
|
287
|
+
results = dragons.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum, :is_fire_breathing)
|
269
288
|
results.should == [ [ 1, 1, 3, 3, 3.0, 3, false ], [ 2, 1, 4, 5, 4.5, 9, true ] ]
|
270
289
|
end
|
271
290
|
end
|
272
291
|
end
|
273
292
|
|
274
293
|
describe 'query path issue' do
|
275
|
-
it
|
276
|
-
dragon =
|
294
|
+
it 'does not break when a query path is specified' do
|
295
|
+
dragon = dragons.first(Dragon.knight.name => 'Chuck')
|
277
296
|
dragon.name.should == 'George'
|
278
297
|
end
|
279
298
|
end
|
280
299
|
end
|
281
300
|
|
282
301
|
shared_examples_for 'count with no arguments' do
|
283
|
-
it '
|
284
|
-
|
302
|
+
it 'counts the results' do
|
303
|
+
dragons.count.should == 3
|
285
304
|
|
286
|
-
|
305
|
+
countries.count.should == 7
|
287
306
|
end
|
288
307
|
|
289
|
-
it '
|
290
|
-
|
308
|
+
it 'counts the results with conditions having operators' do
|
309
|
+
dragons.count(:toes_on_claw.gt => 3).should == 2
|
291
310
|
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
311
|
+
countries.count(:birth_rate.lt => 12).should == 3
|
312
|
+
countries.count(:population.gt => 1000000000).should == 1
|
313
|
+
countries.count(:population.gt => 2000000000).should == 0
|
314
|
+
countries.count(:population.lt => 10).should == 0
|
296
315
|
end
|
297
316
|
|
298
|
-
it '
|
317
|
+
it 'counts the results with raw conditions' do
|
299
318
|
dragon_statement = 'is_fire_breathing = ?'
|
300
|
-
|
301
|
-
|
319
|
+
dragons.count(:conditions => [ dragon_statement, false ]).should == 1
|
320
|
+
dragons.count(:conditions => [ dragon_statement, true ]).should == 2
|
302
321
|
end
|
303
322
|
end
|
metadata
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-aggregates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 15424023
|
5
|
+
prerelease: 6
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
- rc
|
11
|
+
- 1
|
12
|
+
version: 1.2.0.rc1
|
6
13
|
platform: ruby
|
7
14
|
authors:
|
8
15
|
- Foy Savas
|
@@ -10,53 +17,74 @@ autorequire:
|
|
10
17
|
bindir: bin
|
11
18
|
cert_chain: []
|
12
19
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
20
|
+
date: 2011-09-09 00:00:00 Z
|
15
21
|
dependencies:
|
16
22
|
- !ruby/object:Gem::Dependency
|
17
|
-
|
18
|
-
|
23
|
+
type: :runtime
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
19
25
|
none: false
|
20
26
|
requirements:
|
21
27
|
- - ~>
|
22
28
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
29
|
+
hash: 15424023
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 2
|
33
|
+
- 0
|
34
|
+
- rc
|
35
|
+
- 1
|
36
|
+
version: 1.2.0.rc1
|
25
37
|
prerelease: false
|
26
|
-
|
38
|
+
requirement: *id001
|
39
|
+
name: dm-core
|
27
40
|
- !ruby/object:Gem::Dependency
|
28
|
-
|
29
|
-
|
41
|
+
type: :development
|
42
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
30
43
|
none: false
|
31
44
|
requirements:
|
32
45
|
- - ~>
|
33
46
|
- !ruby/object:Gem::Version
|
34
|
-
|
35
|
-
|
47
|
+
hash: 7
|
48
|
+
segments:
|
49
|
+
- 1
|
50
|
+
- 6
|
51
|
+
- 4
|
52
|
+
version: 1.6.4
|
36
53
|
prerelease: false
|
37
|
-
|
54
|
+
requirement: *id002
|
55
|
+
name: jeweler
|
38
56
|
- !ruby/object:Gem::Dependency
|
39
|
-
|
40
|
-
|
57
|
+
type: :development
|
58
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
41
59
|
none: false
|
42
60
|
requirements:
|
43
61
|
- - ~>
|
44
62
|
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
63
|
+
hash: 63
|
64
|
+
segments:
|
65
|
+
- 0
|
66
|
+
- 9
|
67
|
+
- 2
|
68
|
+
version: 0.9.2
|
47
69
|
prerelease: false
|
48
|
-
|
70
|
+
requirement: *id003
|
71
|
+
name: rake
|
49
72
|
- !ruby/object:Gem::Dependency
|
50
|
-
|
51
|
-
|
73
|
+
type: :development
|
74
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
52
75
|
none: false
|
53
76
|
requirements:
|
54
77
|
- - ~>
|
55
78
|
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
|
79
|
+
hash: 31
|
80
|
+
segments:
|
81
|
+
- 1
|
82
|
+
- 3
|
83
|
+
- 2
|
84
|
+
version: 1.3.2
|
58
85
|
prerelease: false
|
59
|
-
|
86
|
+
requirement: *id004
|
87
|
+
name: rspec
|
60
88
|
description: DataMapper plugin providing support for aggregates on collections
|
61
89
|
email: foysavas [a] gmail [d] com
|
62
90
|
executables: []
|
@@ -95,7 +123,6 @@ files:
|
|
95
123
|
- tasks/spec.rake
|
96
124
|
- tasks/yard.rake
|
97
125
|
- tasks/yardstick.rake
|
98
|
-
has_rdoc: true
|
99
126
|
homepage: http://github.com/datamapper/dm-aggregates
|
100
127
|
licenses: []
|
101
128
|
|
@@ -109,25 +136,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
136
|
requirements:
|
110
137
|
- - ">="
|
111
138
|
- !ruby/object:Gem::Version
|
139
|
+
hash: 3
|
140
|
+
segments:
|
141
|
+
- 0
|
112
142
|
version: "0"
|
113
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
144
|
none: false
|
115
145
|
requirements:
|
116
|
-
- - "
|
146
|
+
- - ">"
|
117
147
|
- !ruby/object:Gem::Version
|
118
|
-
|
148
|
+
hash: 25
|
149
|
+
segments:
|
150
|
+
- 1
|
151
|
+
- 3
|
152
|
+
- 1
|
153
|
+
version: 1.3.1
|
119
154
|
requirements: []
|
120
155
|
|
121
156
|
rubyforge_project: datamapper
|
122
|
-
rubygems_version: 1.
|
157
|
+
rubygems_version: 1.8.10
|
123
158
|
signing_key:
|
124
159
|
specification_version: 3
|
125
160
|
summary: DataMapper plugin providing support for aggregates on collections
|
126
|
-
test_files:
|
127
|
-
|
128
|
-
- spec/isolated/require_before_setup_spec.rb
|
129
|
-
- spec/isolated/require_spec.rb
|
130
|
-
- spec/public/collection_spec.rb
|
131
|
-
- spec/public/model_spec.rb
|
132
|
-
- spec/public/shared/aggregate_shared_spec.rb
|
133
|
-
- spec/spec_helper.rb
|
161
|
+
test_files: []
|
162
|
+
|