Skip to content

Commit 67356f2

Browse files
committed
Do not allow passing the column name to count when a block is passed
1 parent d97980a commit 67356f2

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Do not allow passing the column name to `count` when a block is passed.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove delegation of missing methods in a relation to arel.
26

37
*Rafael Mendonça França*

activerecord/lib/active_record/relation/calculations.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,13 @@ module Calculations
4141
def count(column_name = nil)
4242
if block_given?
4343
unless column_name.nil?
44-
ActiveSupport::Deprecation.warn \
45-
"When `count' is called with a block, it ignores other arguments. " \
46-
"This behavior is now deprecated and will result in an ArgumentError in Rails 6.0."
44+
raise ArgumentError, "Column name argument is not supported when a block is passed."
4745
end
4846

49-
return super()
47+
super()
48+
else
49+
calculate(:count, column_name)
5050
end
51-
52-
calculate(:count, column_name)
5351
end
5452

5553
# Calculates the average value on a given column. Returns +nil+ if there's

activerecord/test/cases/calculations_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -917,9 +917,9 @@ def test_group_by_attribute_with_custom_type
917917
assert_equal({ "proposed" => 2, "published" => 2 }, Book.group(:status).count)
918918
end
919919

920-
def test_deprecate_count_with_block_and_column_name
921-
assert_deprecated do
922-
assert_equal 6, Account.count(:firm_id) { true }
920+
def test_count_with_block_and_column_name_raises_an_error
921+
assert_raises(ArgumentError) do
922+
Account.count(:firm_id) { true }
923923
end
924924
end
925925

0 commit comments

Comments
 (0)