From 0ac4b769eff64fd289318949799b12dcfd0f21d7 Mon Sep 17 00:00:00 2001 From: Mike Gunderloy Date: Sat, 28 Feb 2009 11:01:13 -0600 Subject: [PATCH] Tests for scoped find with having --- activerecord/lib/active_record/base.rb | 4 +++- activerecord/test/cases/base_test.rb | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 55ab1fa..fa7b2dc 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1759,7 +1759,9 @@ module ActiveRecord #:nodoc: scope = scope(:find) if :auto == scope if scope && (scoped_group = scope[:group]) sql << " GROUP BY #{scoped_group}" - sql << " HAVING #{scoped_having}" if (scoped_having = scope[:having]) + if (scoped_having = scope[:having]) + sql << " HAVING #{scoped_having}" + end end end end diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 973bb56..f51b526 100755 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1755,6 +1755,13 @@ class BasicsTest < ActiveRecord::TestCase end end + def test_scoped_find_with_group_and_having + developers = Developer.with_scope(:find => { :group => 'salary', :having => "SUM(salary) > 10000", :select => "SUM(salary) as salary" }) do + Developer.find(:all) + end + assert_equal 3, developers.size + end + def test_find_last last = Developer.find :last assert_equal last, Developer.find(:first, :order => 'id desc') -- 1.6.1