Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Merge pull request #457 from jwforres/bug_1006255_match_cart_descrip_…
Browse files Browse the repository at this point in the history
…by_whole_word

Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Sep 10, 2013
2 parents ce0334f + fb3f5e7 commit bad22d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/rhc/cartridge_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ def match_cart(cart, search)
search = search.to_s.downcase.gsub(/[_\-\s]/,' ')
[
cart.name,
cart.description,
(cart.tags || []).join(' '),
].compact.any?{ |s| s.present? && s.downcase.gsub(/[_\-\s]/,' ').include?(search) }
].compact.any?{ |s| s.present? && s.downcase.gsub(/[_\-\s]/,' ').include?(search) } ||
search.length > 2 && [
cart.description
].compact.any?{ |s| s.present? && !s.downcase.match(/\b#{search}\b/).nil? }
end

def web_carts_only
Expand Down
5 changes: 4 additions & 1 deletion spec/rhc/helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,11 +434,14 @@ def options
it{ subject.send(:match_cart, cart, 'foo').should be_false }
end
context 'with simple strings' do
let(:cart){ OpenStruct.new(:name => 'FOO-more_max any', :description => 'bar', :tags => [:baz]) }
let(:cart){ OpenStruct.new(:name => 'FOO-more_max any', :description => 'bar word', :tags => [:baz]) }
it{ subject.send(:match_cart, cart, 'foo').should be_true }
it{ subject.send(:match_cart, cart, 'fo').should be_true }
it{ subject.send(:match_cart, cart, 'oo').should be_true }
it{ subject.send(:match_cart, cart, 'bar').should be_true }
it{ subject.send(:match_cart, cart, 'word').should be_true }
it{ subject.send(:match_cart, cart, 'bar word').should be_true }
it{ subject.send(:match_cart, cart, 'wor').should be_false }
it{ subject.send(:match_cart, cart, 'baz').should be_true }
it{ subject.send(:match_cart, cart, 'more max').should be_true }
it{ subject.send(:match_cart, cart, 'foo more max any').should be_true }
Expand Down

0 comments on commit bad22d6

Please sign in to comment.