提交 abb1bd2e 编写于 作者: P Pratik Naik

Ensure AssociationCollection#count works with empty condition. [#271...

Ensure AssociationCollection#count works with empty condition. [#271 state:resolved] [Jan De Poorter]
上级 4d248543
...@@ -9,7 +9,7 @@ def count(*args) ...@@ -9,7 +9,7 @@ def count(*args)
@reflection.klass.count_by_sql(@finder_sql) @reflection.klass.count_by_sql(@finder_sql)
else else
column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args) column_name, options = @reflection.klass.send(:construct_count_options_from_args, *args)
options[:conditions] = options[:conditions].nil? ? options[:conditions] = options[:conditions].blank? ?
@finder_sql : @finder_sql :
@finder_sql + " AND (#{sanitize_sql(options[:conditions])})" @finder_sql + " AND (#{sanitize_sql(options[:conditions])})"
options[:include] ||= @reflection.options[:include] options[:include] ||= @reflection.options[:include]
......
...@@ -32,6 +32,10 @@ def test_counting ...@@ -32,6 +32,10 @@ def test_counting
assert_equal 2, Firm.find(:first).plain_clients.count assert_equal 2, Firm.find(:first).plain_clients.count
end end
def test_counting_with_empty_hash_conditions
assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => {})
end
def test_counting_with_single_conditions def test_counting_with_single_conditions
assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => '1=1') assert_equal 2, Firm.find(:first).plain_clients.count(:conditions => '1=1')
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册