Skip to content

Commit

Permalink
search_count on a stored scope should not leave :ids_only set and res…
Browse files Browse the repository at this point in the history
…ults populated
  • Loading branch information
labria authored and pat committed Dec 8, 2009
1 parent 8585bf1 commit e751332
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/thinking_sphinx/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ def method_missing(method, *args, &block)
return self
elsif method == :search_count
@options[:ids_only] = true
return self.total_entries
results_count = self.total_entries
@options[:ids_only] = false
@populated = false
return results_count
elsif method.to_s[/^each_with_.*/].nil? && !@array.respond_to?(method)
super
elsif !SafeMethods.include?(method.to_s)
Expand Down
7 changes: 7 additions & 0 deletions spec/thinking_sphinx/active_record/scopes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@

Alpha.by_name('foo').search_count
end

it "should not leave the :ids_only option set and the results populated" do
stored_scope = Alpha.by_name('foo')
stored_scope.search_count
stored_scope.options[:ids_only].should be_false
stored_scope.populated?.should be_false
end
end

end

0 comments on commit e751332

Please sign in to comment.