Skip to content
Browse files

Fixed total_entries method when the index has no data.

  • Loading branch information...
1 parent 4c0e214 commit d3757ca860108a6d5830b153df4cea4596fe8885 aassarattanakul committed Nov 25, 2009
Showing with 10 additions and 0 deletions.
  1. +2 −0 lib/thinking_sphinx/search.rb
  2. +8 −0 spec/lib/thinking_sphinx/search_spec.rb
View
2 lib/thinking_sphinx/search.rb
@@ -168,6 +168,8 @@ def total_pages
#
def total_entries
populate
+ return 0 if @results[:total_found].nil?
+
@total_entries ||= @results[:total_found]
end
View
8 spec/lib/thinking_sphinx/search_spec.rb
@@ -868,6 +868,14 @@
it "should return the total number of results, not just the amount on the page" do
ThinkingSphinx::Search.new.total_entries.should == 41
end
+
+ it "should return 0 if there is no index and therefore no results" do
+ @client.stub!(:query => {
+ :matches => [], :total_found => nil
+ })
+
+ ThinkingSphinx::Search.new.total_entries.should == 0
+ end
end
describe '#offset' do

0 comments on commit d3757ca

Please sign in to comment.
Something went wrong with that request. Please try again.