From 6543426c73fa9ccf3649d7cbacbbb0fda9b6a099 Mon Sep 17 00:00:00 2001 From: stopdropandrew Date: Sat, 7 Mar 2009 15:26:56 +0000 Subject: Ensure calculations respect scoped :select [#1334 state:resolved] Signed-off-by: Pratik Naik --- activerecord/test/cases/calculations_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'activerecord/test/cases') diff --git a/activerecord/test/cases/calculations_test.rb b/activerecord/test/cases/calculations_test.rb index c158706645..0257fe57cb 100644 --- a/activerecord/test/cases/calculations_test.rb +++ b/activerecord/test/cases/calculations_test.rb @@ -264,6 +264,17 @@ class CalculationsTest < ActiveRecord::TestCase assert_equal 4, Account.count(:distinct => true, :include => :firm, :select => :credit_limit) end + def test_should_count_scoped_select + Account.update_all("credit_limit = 50") + assert_equal 1, Account.scoped(:select => "DISTINCT credit_limit").count + end + + def test_should_count_scoped_select_with_options + Account.update_all("credit_limit = 50") + Account.first.update_attribute('credit_limit', 49) + assert_equal 1, Account.scoped(:select => "DISTINCT credit_limit").count(:conditions => [ 'credit_limit >= 50'] ) + end + def test_should_count_manual_select_with_include assert_equal 6, Account.count(:select => "DISTINCT accounts.id", :include => :firm) end -- cgit v1.2.3