mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
111968d402
commit
d1545bcf94
2 changed files with 10 additions and 3 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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'"
|
||||
|
||||
|
|
Loading…
Reference in a new issue