Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
Merge pull request #46 from pfac/pfac-honour-nil-limit
Browse files Browse the repository at this point in the history
Nil limit
  • Loading branch information
mezis committed Mar 20, 2015
2 parents ad9fc87 + a0778d8 commit b62b141
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fuzzily/searchable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def fuzzily_searchable(*fields)
private

def _find_by_fuzzy(_o, pattern, options={})
options[:limit] ||= 10
options[:limit] ||= 10 unless options.has_key? :limit
options[:offset] ||= 0

trigrams = _o.trigram_class_name.constantize.
Expand Down
12 changes: 12 additions & 0 deletions spec/fuzzily/searchable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ def Stuff.name ; 'Stuff' ; end
subject.find_by_fuzzy_name('Paris', :limit => 2).length.should == 2
end

it 'limits results to 10 if limit option is not given' do
subject.fuzzily_searchable :name
30.times { subject.create!(:name => 'Paris') }
subject.find_by_fuzzy_name('Paris').length.should == 10
end

it 'does not limit results it limit option is present and is nil' do
subject.fuzzily_searchable :name
30.times { subject.create!(:name => 'Paris') }
subject.find_by_fuzzy_name('Paris', :limit => nil).length.should == 30
end

it 'honours offset option' do
subject.fuzzily_searchable :name
3.times { subject.create!(:name => 'Paris') }
Expand Down

0 comments on commit b62b141

Please sign in to comment.