Skip to content
Permalink
Browse files
Do not allow passing the column name to count when a block is passed
  • Loading branch information
rafaelfranca committed Jan 17, 2019
1 parent d97980a commit 67356f2034ab41305af7218f7c8b2fee2d614129
@@ -1,3 +1,7 @@
* Do not allow passing the column name to `count` when a block is passed.

*Rafael Mendonça França*

* Remove delegation of missing methods in a relation to arel.

*Rafael Mendonça França*
@@ -41,15 +41,13 @@ module Calculations
def count(column_name = nil)
if block_given?
unless column_name.nil?
ActiveSupport::Deprecation.warn \
"When `count' is called with a block, it ignores other arguments. " \
"This behavior is now deprecated and will result in an ArgumentError in Rails 6.0."
raise ArgumentError, "Column name argument is not supported when a block is passed."
end

return super()
super()
else
calculate(:count, column_name)
end

calculate(:count, column_name)
end

# Calculates the average value on a given column. Returns +nil+ if there's
@@ -917,9 +917,9 @@ def test_group_by_attribute_with_custom_type
assert_equal({ "proposed" => 2, "published" => 2 }, Book.group(:status).count)
end

def test_deprecate_count_with_block_and_column_name
assert_deprecated do
assert_equal 6, Account.count(:firm_id) { true }
def test_count_with_block_and_column_name_raises_an_error
assert_raises(ArgumentError) do
Account.count(:firm_id) { true }
end
end

0 comments on commit 67356f2

Please sign in to comment.