From 8fde84b7fd8563ee237166c610ef917a634ca63c Mon Sep 17 00:00:00 2001 From: Emili Parreno Date: Thu, 21 May 2009 12:27:52 +0200 Subject: [PATCH] fix for patch 2626 --- activerecord/lib/active_record/calculations.rb | 12 ++++++++++-- activerecord/test/cases/calculations_test.rb | 8 ++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/activerecord/lib/active_record/calculations.rb b/activerecord/lib/active_record/calculations.rb index 7afa7c4..1a1d05f 100644 --- a/activerecord/lib/active_record/calculations.rb +++ b/activerecord/lib/active_record/calculations.rb @@ -149,10 +149,18 @@ module ActiveRecord # selects specified by scopes case args.size when 0 - column_name = scope(:find)[:select] if scope(:find) + if (scope(:find) && scope(:find)[:select] =~ /.*,.*/) + column_name = :all + elsif scope(:find) + column_name = scope(:find)[:select] + end when 1 if args[0].is_a?(Hash) - column_name = scope(:find)[:select] if scope(:find) + if (scope(:find) && scope(:find)[:select] =~ /.*,.*/) + column_name = :all + elsif scope(:find) + column_name = scope(:find)[:select] + end options = args[0] else column_name = args[0] diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index fd455e0..8ad7577 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -268,7 +268,15 @@ class CalculationsTest < ActiveRecord::TestCase Account.update_all("credit_limit = NULL") assert_equal 0, Account.scoped(:select => "credit_limit").count end + + def test_should_count_scoped_select_with_multiple_fileds + Account.update_all("credit_limit = NULL") + Account.last.update_attribute('credit_limit', 49) + Account.first.update_attribute('credit_limit', 51) + assert_equal 1, Account.scoped(:select => "id, credit_limit").count(:conditions => ['credit_limit >= 50']) + end + def test_should_count_scoped_select_with_options Account.update_all("credit_limit = NULL") Account.last.update_attribute('credit_limit', 49) -- 1.6.0.2