Permalink
Browse files

Make NullRelation a bit more like a real relation by returning 0 for …

…#calculate(:count)
  • Loading branch information...
1 parent 86cc141 commit a2e607e1055dcede27970ccd7f5b89a1ddee8c32 @Empact Empact committed May 10, 2013
Showing with 8 additions and 3 deletions.
  1. +5 −1 activerecord/lib/active_record/null_relation.rb
  2. +3 −2 activerecord/test/cases/relations_test.rb
@@ -55,7 +55,11 @@ def sum(*)
end
def calculate(_operation, _column_name, _options = {})
- nil
+ if _operation == :count
+ 0
+ else
+ nil
+ end
end
def exists?(_id = false)
@@ -278,8 +278,9 @@ def test_null_relation_content_size_methods
def test_null_relation_calculations_methods
assert_no_queries do
- assert_equal 0, Developer.none.count
- assert_equal nil, Developer.none.calculate(:average, 'salary')
+ assert_equal 0, Developer.none.count
+ assert_equal 0, Developer.none.calculate(:count, nil, {})
+ assert_equal nil, Developer.none.calculate(:average, 'salary')
end
end

0 comments on commit a2e607e

Please sign in to comment.