From d3757ca860108a6d5830b153df4cea4596fe8885 Mon Sep 17 00:00:00 2001 From: aassarattanakul Date: Wed, 25 Nov 2009 10:52:46 -0600 Subject: [PATCH] Fixed total_entries method when the index has no data. --- lib/thinking_sphinx/search.rb | 2 ++ spec/lib/thinking_sphinx/search_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/thinking_sphinx/search.rb b/lib/thinking_sphinx/search.rb index 7397a4584..2fa1a1a3d 100644 --- a/lib/thinking_sphinx/search.rb +++ b/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 diff --git a/spec/lib/thinking_sphinx/search_spec.rb b/spec/lib/thinking_sphinx/search_spec.rb index c0facf76e..e683b5283 100644 --- a/spec/lib/thinking_sphinx/search_spec.rb +++ b/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