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 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.1.0'
9
- DO_VERSION = '~> 0.10.2'
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.5.2'
17
- gem 'rake', '~> 0.8.7'
18
- gem 'rspec', '~> 1.3.1'
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.9'
26
- gem 'yard', '~> 0.6'
27
- gem 'yardstick', '~> 0.2'
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
@@ -2,7 +2,7 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  begin
5
- gem 'jeweler', '~> 1.5.2'
5
+ gem 'jeweler', '~> 1.6.4'
6
6
  require 'jeweler'
7
7
 
8
8
  Jeweler::Tasks.new do |gem|
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0.rc1
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{dm-aggregates}
8
- s.version = "1.1.0"
7
+ s.name = "dm-aggregates"
8
+ s.version = "1.2.0.rc1"
9
9
 
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
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 = %q{2011-03-16}
13
- s.description = %q{DataMapper plugin providing support for aggregates on collections}
14
- s.email = %q{foysavas [a] gmail [d] com}
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 = %q{http://github.com/datamapper/dm-aggregates}
49
+ s.homepage = "http://github.com/datamapper/dm-aggregates"
50
50
  s.require_paths = ["lib"]
51
- s.rubyforge_project = %q{datamapper}
52
- s.rubygems_version = %q{1.6.2}
53
- s.summary = %q{DataMapper plugin providing support for aggregates on collections}
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.1.0"])
69
- s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
70
- s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
71
- s.add_development_dependency(%q<rspec>, ["~> 1.3.1"])
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.1.0"])
74
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
75
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
76
- s.add_dependency(%q<rspec>, ["~> 1.3.1"])
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.1.0"])
80
- s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
81
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
82
- s.add_dependency(%q<rspec>, ["~> 1.3.1"])
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
- before :all do
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
- it 'should return 0' do
23
- @dragons.send(method).should == 0
24
- end
16
+ subject { dragons.send(method) }
17
+
18
+ it { should == 0 }
25
19
  end
26
20
  end
27
21
 
28
22
  describe '#min' do
29
- it 'should return nil' do
30
- @dragons.min(:id).should == nil
31
- end
23
+ subject { dragons.min(:id) }
24
+
25
+ it { should be_nil }
32
26
  end
33
27
 
34
28
  describe '#max' do
35
- it 'should return nil' do
36
- @dragons.max(:id).should == nil
37
- end
29
+ subject { dragons.max(:id) }
30
+
31
+ it { should be_nil }
38
32
  end
39
33
 
40
34
  describe '#avg' do
41
- it 'should return nil' do
42
- @dragons.avg(:id).should == nil
43
- end
35
+ subject { dragons.avg(:id) }
36
+
37
+ it { should be_nil }
44
38
  end
45
39
 
46
40
  describe '#sum' do
47
- it 'should return nil' do
48
- @dragons.sum(:id).should == nil
49
- end
41
+ subject { dragons.sum(:id) }
42
+
43
+ it { should be_nil }
50
44
  end
51
45
 
52
46
  describe '#aggregate' do
53
- it 'should return nil' do
54
- @dragons.aggregate(:id).should == []
55
- end
47
+ subject { dragons.aggregate(:id) }
48
+
49
+ it { should == [] }
56
50
  end
57
51
  end
58
52
 
59
- describe 'with collections created with Set operations' do
60
- before do
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 { @collection.size }
57
+ subject { collection.size }
66
58
 
67
59
  it { should == 2 }
68
60
  end
69
61
 
70
62
  describe '#count' do
71
- subject { @collection.count }
63
+ subject { collection.count }
72
64
 
73
65
  it { should == 2 }
74
66
  end
75
67
 
76
68
  describe '#min' do
77
- subject { @collection.min(:toes_on_claw) }
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 { @collection.max(:toes_on_claw) }
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 { @collection.avg(:toes_on_claw) }
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 { @collection.sum(:toes_on_claw) }
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 { @collection.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum)}
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
- describe 'with a collection limited to 1 result' do
99
+ context 'with a collection limited to 1 result' do
100
+ let(:dragons) { Dragon.all(:limit => 1) }
108
101
 
109
- before do
110
- @dragons = Dragon.all(:limit => 1)
111
- end
102
+ describe '#size' do
103
+ subject { dragons.size }
112
104
 
113
- describe "#size" do
114
- it 'should return 1' do
115
- @dragons.size.should == 1
116
- end
105
+ it { should == 1 }
117
106
  end
118
107
 
119
- describe "#count" do
120
- it 'should return 1' do
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
- describe 'with the order reversed by the grouping field' do
130
- before do
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
- it 'should display the results in reverse order' do
135
- @dragons.aggregate(:birth_at, :all.count).should == Dragon.aggregate(:birth_at, :all.count).reverse
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
@@ -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 = 277738.70
23
+ gold_kilo_price = 277738.70
25
24
  @gold_tonne_price = gold_kilo_price * 10000
26
25
 
27
- Country.create(: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
- Country.create(:name => 'United States',
33
- :population => 303824646,
34
- :birth_rate => 14.18,
35
- :gold_reserve_tonnes => 8133.5,
36
- :gold_reserve_value => 8133.5 * @gold_tonne_price)
37
- Country.create(:name => 'Brazil',
38
- :population => 191908598,
39
- :birth_rate => 16.04,
40
- :gold_reserve_tonnes => nil) # example of no stats available
41
- Country.create(:name => 'Russia',
42
- :population => 140702094,
43
- :birth_rate => 11.03,
44
- :gold_reserve_tonnes => 438.2,
45
- :gold_reserve_value => 438.2 * @gold_tonne_price)
46
- Country.create(:name => 'Japan',
47
- :population => 127288419,
48
- :birth_rate => 7.87,
49
- :gold_reserve_tonnes => 765.2,
50
- :gold_reserve_value => 765.2 * @gold_tonne_price)
51
- Country.create(:name => 'Mexico',
52
- :population => 109955400,
53
- :birth_rate => 20.04,
54
- :gold_reserve_tonnes => nil) # example of no stats available
55
- Country.create(:name => 'Germany',
56
- :population => 82369548,
57
- :birth_rate => 8.18,
58
- :gold_reserve_tonnes => 3417.4,
59
- :gold_reserve_value => 3417.4 * @gold_tonne_price)
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
- describe 'with a property name' do
74
- it 'should count the results' do
75
- @dragons.count(:name).should == 2
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 'should count the results with conditions having operators' do
79
- @dragons.count(:name, :toes_on_claw.gt => 3).should == 1
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 'should count the results with raw conditions' do
101
+ it 'counts the results with raw conditions' do
83
102
  statement = 'is_fire_breathing = ?'
84
- @dragons.count(:name, :conditions => [ statement, false ]).should == 1
85
- @dragons.count(:name, :conditions => [ statement, true ]).should == 1
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
- describe 'with no arguments' do
92
- it 'should raise an error' do
93
- lambda { @dragons.min }.should raise_error(ArgumentError)
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
- describe 'with a property name' do
98
- it 'should provide the lowest value of an Integer property' do
99
- @dragons.min(:toes_on_claw).should == 3
100
- @countries.min(:population).should == 82369548
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 'should provide the lowest value of a Float property' do
104
- @countries.min(:birth_rate).should be_kind_of(Float)
105
- @countries.min(:birth_rate).should >= 7.87 - @approx_by # approx match
106
- @countries.min(:birth_rate).should <= 7.87 + @approx_by # approx match
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 'should provide the lowest value of a BigDecimal property' do
110
- @countries.min(:gold_reserve_value).should be_kind_of(BigDecimal)
111
- @countries.min(:gold_reserve_value).should == BigDecimal('1217050983400.0')
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 'should provide the lowest value of a DateTime property' do
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
- @dragons.min(:birth_at).should be_kind_of(DateTime)
117
- @dragons.min(:birth_at).to_s.should == @birth_at.to_s
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 'should provide the lowest value of a Date property' do
122
- @dragons.min(:birth_on).should be_kind_of(Date)
123
- @dragons.min(:birth_on).should == @birth_on
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 'should provide the lowest value of a Time property' do
127
- @dragons.min(:birth_time).should be_kind_of(Time)
128
- @dragons.min(:birth_time).to_s.should == @birth_time.to_s
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 'should provide the lowest value when conditions provided' do
132
- @dragons.min(:toes_on_claw, :is_fire_breathing => true).should == 4
133
- @dragons.min(:toes_on_claw, :is_fire_breathing => false).should == 3
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
- describe 'with no arguments' do
140
- it 'should raise an error' do
141
- lambda { @dragons.max }.should raise_error(ArgumentError)
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
- describe 'with a property name' do
146
- it 'should provide the highest value of an Integer property' do
147
- @dragons.max(:toes_on_claw).should == 5
148
- @countries.max(:population).should == 1330044605
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 'should provide the highest value of a Float property' do
152
- @countries.max(:birth_rate).should be_kind_of(Float)
153
- @countries.max(:birth_rate).should >= 20.04 - @approx_by # approx match
154
- @countries.max(:birth_rate).should <= 20.04 + @approx_by # approx match
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 'should provide the highest value of a BigDecimal property' do
158
- @countries.max(:gold_reserve_value).should == BigDecimal('22589877164500.0')
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 'should provide the highest value of a DateTime property' do
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
- @dragons.min(:birth_at).should be_kind_of(DateTime)
164
- @dragons.min(:birth_at).to_s.should == @birth_at.to_s
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 'should provide the highest value of a Date property' do
169
- @dragons.min(:birth_on).should be_kind_of(Date)
170
- @dragons.min(:birth_on).should == @birth_on
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 'should provide the highest value of a Time property' do
174
- @dragons.min(:birth_time).should be_kind_of(Time)
175
- @dragons.min(:birth_time).to_s.should == @birth_time.to_s
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 'should provide the highest value when conditions provided' do
179
- @dragons.max(:toes_on_claw, :is_fire_breathing => true).should == 5
180
- @dragons.max(:toes_on_claw, :is_fire_breathing => false).should == 3
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
- describe 'with no arguments' do
187
- it 'should raise an error' do
188
- lambda { @dragons.avg }.should raise_error(ArgumentError)
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
- describe 'with a property name' do
193
- it 'should provide the average value of an Integer property' do
194
- @dragons.avg(:toes_on_claw).should be_kind_of(Float)
195
- @dragons.avg(:toes_on_claw).should == 4.0
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 'should provide the average value of a Float property' do
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
- @countries.avg(:birth_rate).should be_kind_of(Float)
201
- @countries.avg(:birth_rate).should >= mean_birth_rate - @approx_by # approx match
202
- @countries.avg(:birth_rate).should <= mean_birth_rate + @approx_by # approx match
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 'should provide the average value of a BigDecimal property' do
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
- @countries.avg(:gold_reserve_value).should be_kind_of(BigDecimal)
208
- @countries.avg(:gold_reserve_value).should == BigDecimal(mean_gold_reserve_value.to_s)
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 'should provide the average value when conditions provided' do
212
- @dragons.avg(:toes_on_claw, :is_fire_breathing => true).should == 4.5
213
- @dragons.avg(:toes_on_claw, :is_fire_breathing => false).should == 3
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
- describe 'with no arguments' do
220
- it 'should raise an error' do
221
- lambda { @dragons.sum }.should raise_error(ArgumentError)
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
- describe 'with a property name' do
226
- it 'should provide the sum of values for an Integer property' do
227
- @dragons.sum(:toes_on_claw).should == 12
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
- @countries.sum(:population).should == total_population
250
+ countries.sum(:population).should == total_population
232
251
  end
233
252
 
234
- it 'should provide the sum of values for a Float property' do
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
- @countries.sum(:gold_reserve_tonnes).should be_kind_of(Float)
237
- @countries.sum(:gold_reserve_tonnes).should >= total_tonnes - @approx_by # approx match
238
- @countries.sum(:gold_reserve_tonnes).should <= total_tonnes + @approx_by # approx match
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 'should provide the sum of values for a BigDecimal property' do
242
- @countries.sum(:gold_reserve_value).should == BigDecimal('37090059214100.0')
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 'should provide the average value when conditions provided' do
246
- @dragons.sum(:toes_on_claw, :is_fire_breathing => true).should == 9
247
- @dragons.sum(:toes_on_claw, :is_fire_breathing => false).should == 3
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
- describe 'with no arguments' do
254
- it 'should raise an error' do
255
- lambda { @dragons.aggregate }.should raise_error(ArgumentError)
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
- describe 'with only aggregate fields specified' do
260
- it 'should provide aggregate results' do
261
- results = @dragons.aggregate(:all.count, :name.count, :toes_on_claw.min, :toes_on_claw.max, :toes_on_claw.avg, :toes_on_claw.sum)
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
- describe 'with aggregate fields and a property to group by' do
267
- it 'should provide aggregate results' do
268
- 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)
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 "should not break when a query path is specified" do
276
- dragon = @dragons.first(Dragon.knight.name => 'Chuck')
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 'should count the results' do
284
- @dragons.count.should == 3
302
+ it 'counts the results' do
303
+ dragons.count.should == 3
285
304
 
286
- @countries.count.should == 7
305
+ countries.count.should == 7
287
306
  end
288
307
 
289
- it 'should count the results with conditions having operators' do
290
- @dragons.count(:toes_on_claw.gt => 3).should == 2
308
+ it 'counts the results with conditions having operators' do
309
+ dragons.count(:toes_on_claw.gt => 3).should == 2
291
310
 
292
- @countries.count(:birth_rate.lt => 12).should == 3
293
- @countries.count(:population.gt => 1000000000).should == 1
294
- @countries.count(:population.gt => 2000000000).should == 0
295
- @countries.count(:population.lt => 10).should == 0
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 'should count the results with raw conditions' do
317
+ it 'counts the results with raw conditions' do
299
318
  dragon_statement = 'is_fire_breathing = ?'
300
- @dragons.count(:conditions => [ dragon_statement, false ]).should == 1
301
- @dragons.count(:conditions => [ dragon_statement, true ]).should == 2
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
- prerelease:
5
- version: 1.1.0
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-03-16 00:00:00 -07:00
14
- default_executable:
20
+ date: 2011-09-09 00:00:00 Z
15
21
  dependencies:
16
22
  - !ruby/object:Gem::Dependency
17
- name: dm-core
18
- requirement: &id001 !ruby/object:Gem::Requirement
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
- version: 1.1.0
24
- type: :runtime
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
- version_requirements: *id001
38
+ requirement: *id001
39
+ name: dm-core
27
40
  - !ruby/object:Gem::Dependency
28
- name: jeweler
29
- requirement: &id002 !ruby/object:Gem::Requirement
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
- version: 1.5.2
35
- type: :development
47
+ hash: 7
48
+ segments:
49
+ - 1
50
+ - 6
51
+ - 4
52
+ version: 1.6.4
36
53
  prerelease: false
37
- version_requirements: *id002
54
+ requirement: *id002
55
+ name: jeweler
38
56
  - !ruby/object:Gem::Dependency
39
- name: rake
40
- requirement: &id003 !ruby/object:Gem::Requirement
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
- version: 0.8.7
46
- type: :development
63
+ hash: 63
64
+ segments:
65
+ - 0
66
+ - 9
67
+ - 2
68
+ version: 0.9.2
47
69
  prerelease: false
48
- version_requirements: *id003
70
+ requirement: *id003
71
+ name: rake
49
72
  - !ruby/object:Gem::Dependency
50
- name: rspec
51
- requirement: &id004 !ruby/object:Gem::Requirement
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
- version: 1.3.1
57
- type: :development
79
+ hash: 31
80
+ segments:
81
+ - 1
82
+ - 3
83
+ - 2
84
+ version: 1.3.2
58
85
  prerelease: false
59
- version_requirements: *id004
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
- version: "0"
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.6.2
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
- - spec/isolated/require_after_setup_spec.rb
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
+