diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index f077818..de552de 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -164,6 +164,7 @@ module ActiveRecord raise ArgumentError, "Unexpected parameters passed to count(): #{args.inspect}" end + column_name = :all if column_name.to_s.index(',') [column_name || :all, options] end diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index 56dcdea..54034b4 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -277,6 +277,10 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 1, Account.scoped(:select => "credit_limit").count(:conditions => ['credit_limit >= 50']) end + def test_could_should_ignore_scoped_select_with_comma + assert_equal 6, Account.scoped(:select => "credit_limit, firm_id").count + end + def test_should_count_manual_select_with_include assert_equal 6, Account.count(:select => "DISTINCT accounts.id", :include => :firm) end