Changeset 9243
- Timestamp:
- 04/08/08 05:20:33 (8 months ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/calculations.rb (modified) (1 diff)
- trunk/activerecord/test/cases/calculations_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r9235 r9243 1 1 *SVN* 2 3 * ActiveRecord::Base#sum defaults to 0 if no rows are returned. Closes #11550 [kamal] 2 4 3 5 * Ensure that respond_to? considers dynamic finder methods. Closes #11538. [floehopper] trunk/activerecord/lib/active_record/calculations.rb
r9223 r9243 72 72 # Person.sum('age') 73 73 def sum(column_name, options = {}) 74 calculate(:sum, column_name, options) 74 calculate(:sum, column_name, options) || 0 75 75 end 76 76 trunk/activerecord/test/cases/calculations_test.rb
r9223 r9243 96 96 def test_should_sum_field_with_conditions 97 97 assert_equal 105, Account.sum(:credit_limit, :conditions => 'firm_id = 6') 98 end 99 100 def test_should_return_zero_if_sum_conditions_return_nothing 101 assert_equal 0, Account.sum(:credit_limit, :conditions => '1 = 2') 98 102 end 99 103