aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authoryui-knk <spiketeika@gmail.com>2015-09-23 10:08:46 +0900
committeryui-knk <spiketeika@gmail.com>2015-09-23 10:08:46 +0900
commit0f6d47d88f1ba771e8c463dcf12ee53cb875454d (patch)
tree64944f5560be6198aa42819927750ce5f5d485f1 /activerecord/lib
parent5e4df5c674a9849839fc10111ba6e88910d945b2 (diff)
downloadrails-0f6d47d88f1ba771e8c463dcf12ee53cb875454d.tar.gz
rails-0f6d47d88f1ba771e8c463dcf12ee53cb875454d.tar.bz2
rails-0f6d47d88f1ba771e8c463dcf12ee53cb875454d.zip
Fix arguments of `AR::Calculations#sum`
Arguments of `#sum` does not match with other shortcuts methods (count, average, minimum, and maximum). This commit fix these two points: * call `super` with only block arguments First argument of `super` method, `Enumerable#sum`, is `identity` and first argument of `AR::Calculations#sum` is `column_name`. `Enumerable#sum` does not expect `column_name` to be passed. * Change first argument of `sum` from array arguemnt to single argument to match other shortcuts methods. When `sum` accept array arguemnt, user can pass multi arguments and an exception is raised from `calculate`.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/calculations.rb6
1 files changed, 3 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/calculations.rb b/activerecord/lib/active_record/relation/calculations.rb
index 0f6015fa93..922cbc05eb 100644
--- a/activerecord/lib/active_record/relation/calculations.rb
+++ b/activerecord/lib/active_record/relation/calculations.rb
@@ -70,9 +70,9 @@ module ActiveRecord
# +calculate+ for examples with options.
#
# Person.sum(:age) # => 4562
- def sum(*args)
- return super if block_given?
- calculate(:sum, *args)
+ def sum(column_name = nil, &block)
+ return super &block if block_given?
+ calculate(:sum, column_name)
end
# This calculates aggregate values in the given column. Methods for count, sum, average,