public
Fork of sam/dm-more
Description: Extras for DataMapper, including bridges to DataObjects::Migrations and Merb::DataMapper
Homepage: http://datamapper.org
Clone URL: git://github.com/myabc/dm-more.git
Search Repo:
Updated Model#avg to typecast results for Integer properties as Floats
dkubb (author)
Wed May 14 15:07:53 -0700 2008
commit  62fef41cfd57c87a2f6201bc6cbe1bb3254a8439
tree    ace08bc45064dff5c20c26fed1cdd15f75d749aa
parent  8c9fbb16fae576fdba9f2990a25da315dac91cd9
...
21
22
23
24
 
25
26
27
...
21
22
23
 
24
25
26
27
0
@@ -21,7 +21,7 @@ module DataMapper
0
       def avg(respository, property, query)
0
         parameters = query.parameters
0
         avg = query(aggregate_value_statement(:avg, property, query), *parameters).first
0
- property.typecast(avg)
0
+ property.type == Fixnum ? avg.to_f : property.typecast(avg)
0
       end
0
 
0
       def sum(respository, property, query)
...
188
189
190
191
 
 
192
193
194
...
205
206
207
208
 
209
210
211
...
188
189
190
 
191
192
193
194
195
...
206
207
208
 
209
210
211
212
0
@@ -188,7 +188,8 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
0
 
0
       describe 'with a property name' do
0
         it 'should provide the average value of an Integer property' do
0
- Dragon.avg(:toes_on_claw).should == 4
0
+ Dragon.avg(:toes_on_claw).should be_kind_of(Float)
0
+ Dragon.avg(:toes_on_claw).should == 4.0
0
         end
0
 
0
         it 'should provide the average value of a Float property' do
0
@@ -205,7 +206,7 @@ if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
0
         end
0
 
0
         it 'should provide the average value when conditions provided' do
0
- Dragon.avg(:toes_on_claw, :is_fire_breathing => true).should == 4
0
+ Dragon.avg(:toes_on_claw, :is_fire_breathing => true).should == 4.5
0
           Dragon.avg(:toes_on_claw, :is_fire_breathing => false).should == 3
0
         end
0
       end

Comments

    No one has commented yet.