Skip to content
This repository
Browse code

Stop accepting `options` for `Relation#average`, `Relation#minimum`, …

…`Relation#maximum`, `Relation#calculate`, `perform_calculation`, `NullRelation#calculate` as they isn't used anymore.
  • Loading branch information...
commit 42d3d3c217d158873409c50c429ae711a0306d99 1 parent 4ce643d
Vipul A M vipulnsward authored
2  activerecord/lib/active_record/null_relation.rb
@@ -50,7 +50,7 @@ def sum(*)
50 50 0
51 51 end
52 52
53   - def calculate(_operation, _column_name, _options = {})
  53 + def calculate(_operation, _column_name)
54 54 if _operation == :count
55 55 0
56 56 else
20 activerecord/lib/active_record/relation/calculations.rb
@@ -27,8 +27,8 @@ def count(column_name = nil)
27 27 # no row. See +calculate+ for examples with options.
28 28 #
29 29 # Person.average(:age) # => 35.8
30   - def average(column_name, options = {})
31   - calculate(:average, column_name, options)
  30 + def average(column_name)
  31 + calculate(:average, column_name)
32 32 end
33 33
34 34 # Calculates the minimum value on a given column. The value is returned
@@ -36,8 +36,8 @@ def average(column_name, options = {})
36 36 # +calculate+ for examples with options.
37 37 #
38 38 # Person.minimum(:age) # => 7
39   - def minimum(column_name, options = {})
40   - calculate(:minimum, column_name, options)
  39 + def minimum(column_name)
  40 + calculate(:minimum, column_name)
41 41 end
42 42
43 43 # Calculates the maximum value on a given column. The value is returned
@@ -45,8 +45,8 @@ def minimum(column_name, options = {})
45 45 # +calculate+ for examples with options.
46 46 #
47 47 # Person.maximum(:age) # => 93
48   - def maximum(column_name, options = {})
49   - calculate(:maximum, column_name, options)
  48 + def maximum(column_name)
  49 + calculate(:maximum, column_name)
50 50 end
51 51
52 52 # Calculates the sum of values on a given column. The value is returned
@@ -89,15 +89,15 @@ def sum(*args)
89 89 # Person.group(:last_name).having("min(age) > 17").minimum(:age)
90 90 #
91 91 # Person.sum("2 * age")
92   - def calculate(operation, column_name, options = {})
  92 + def calculate(operation, column_name)
93 93 if column_name.is_a?(Symbol) && attribute_alias?(column_name)
94 94 column_name = attribute_alias(column_name)
95 95 end
96 96
97 97 if has_include?(column_name)
98   - construct_relation_for_association_calculations.calculate(operation, column_name, options)
  98 + construct_relation_for_association_calculations.calculate(operation, column_name)
99 99 else
100   - perform_calculation(operation, column_name, options)
  100 + perform_calculation(operation, column_name)
101 101 end
102 102 end
103 103
@@ -180,7 +180,7 @@ def has_include?(column_name)
180 180 eager_loading? || (includes_values.present? && (column_name || references_eager_loaded_tables?))
181 181 end
182 182
183   - def perform_calculation(operation, column_name, options = {})
  183 + def perform_calculation(operation, column_name)
184 184 operation = operation.to_s.downcase
185 185
186 186 # If #count is used with #distinct / #uniq it is considered distinct. (eg. relation.distinct.count)
2  activerecord/test/cases/relations_test.rb
@@ -295,7 +295,7 @@ def test_null_relation_content_size_methods
295 295 def test_null_relation_calculations_methods
296 296 assert_no_queries do
297 297 assert_equal 0, Developer.none.count
298   - assert_equal 0, Developer.none.calculate(:count, nil, {})
  298 + assert_equal 0, Developer.none.calculate(:count, nil)
299 299 assert_equal nil, Developer.none.calculate(:average, 'salary')
300 300 end
301 301 end

0 comments on commit 42d3d3c

Please sign in to comment.
Something went wrong with that request. Please try again.