<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -136,6 +136,10 @@ module ActiveRecord
         end
       end
 
+      def sum(*args)
+        super || 0
+      end
+
       def empty?
         @found ? @found.empty? : count.zero?
       end</diff>
      <filename>lib/named_scope/named_scope.rb</filename>
    </modified>
    <modified>
      <diff>@@ -29,6 +29,13 @@ class NamedScopeTest &lt; NamedScope::TestCase
         @david.reload.posts.last
       end
     end
+    
+    should 'return 0 when calculating on an empty set returned from a scope' do
+      new_author = Factory :author
+      assert_equal 0, @david.posts.containing_the_letter_a.sum('comments_count')      # non-empty
+      assert_equal 0, new_author.posts.containing_the_letter_a.count                  # empty
+      assert_equal 0, new_author.posts.containing_the_letter_a.sum('comments_count')
+    end
 
   end
   </diff>
      <filename>test/named_scope_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>6f12f9f302fa83cc8cf63ba5d313df544dd91c39</id>
    </parent>
  </parents>
  <author>
    <name>Brennan Dunn</name>
    <email>me@brennandunn.com</email>
  </author>
  <url>http://github.com/metaskills/named_scope/commit/c3cb61f34bbbf6450b7b6cc00f382ff8008e536f</url>
  <id>c3cb61f34bbbf6450b7b6cc00f382ff8008e536f</id>
  <committed-date>2008-10-17T11:10:43-07:00</committed-date>
  <authored-date>2008-10-17T11:10:43-07:00</authored-date>
  <message>Made #sum default to 0 when nil</message>
  <tree>71076133b5d098496eee0813b5ff69fcb853a7f7</tree>
  <committer>
    <name>Brennan Dunn</name>
    <email>me@brennandunn.com</email>
  </committer>
</commit>
