aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorAkira Matsuda <ronnie@dio.jp>2011-07-08 12:16:32 +0900
committerAkira Matsuda <ronnie@dio.jp>2011-07-09 20:14:41 +0900
commitd1545bcf94af287fca1fc34e0f9c7cfda56ff130 (patch)
treebc4c292b99397001ab79bb02a8b744a88f8ad283 /activerecord
parent111968d4024fdccc386979551cdfc7799b39cff0 (diff)
downloadrails-d1545bcf94af287fca1fc34e0f9c7cfda56ff130.tar.gz
rails-d1545bcf94af287fca1fc34e0f9c7cfda56ff130.tar.bz2
rails-d1545bcf94af287fca1fc34e0f9c7cfda56ff130.zip
fix AR having() not to raise NoMethodError when the given argument does not respond to empty?
having raises NoMethodError: undefined method `empty?' when a Fixnum or Date/Time were passed via varargs
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb6
-rw-r--r--activerecord/test/cases/finder_test.rb7
2 files changed, 10 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index d17861f407..8bd4732c0c 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -96,11 +96,11 @@ module ActiveRecord
relation
end
- def having(*args)
- return self if args.blank?
+ def having(opts, *rest)
+ return self if opts.blank?
relation = clone
- relation.having_values += build_where(*args)
+ relation.having_values += build_where(opts, rest)
relation
end
diff --git a/activerecord/test/cases/finder_test.rb b/activerecord/test/cases/finder_test.rb
index 4e75eafe3d..8f392609df 100644
--- a/activerecord/test/cases/finder_test.rb
+++ b/activerecord/test/cases/finder_test.rb
@@ -159,6 +159,13 @@ class FinderTest < ActiveRecord::TestCase
assert developers.all? { |developer| developer.salary > 10000 }
end
+ def test_find_with_group_and_sanitized_having_method
+ developers = Developer.group(:salary).having("sum(salary) > ?", 10000).select('salary').all
+ assert_equal 3, developers.size
+ assert_equal 3, developers.map(&:salary).uniq.size
+ assert developers.all? { |developer| developer.salary > 10000 }
+ end
+
def test_find_with_entire_select_statement
topics = Topic.find_by_sql "SELECT * FROM topics WHERE author_name = 'Mary'"