item search throws exception if not given query
This commit is contained in:
parent
5b86e640b0
commit
ae09fe0515
2 changed files with 11 additions and 0 deletions
|
@ -14,6 +14,8 @@ class Item < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search(query)
|
def self.search(query)
|
||||||
|
query = query.strip if query
|
||||||
|
raise ArgumentError, "Please provide a search query" if query.blank?
|
||||||
query_conditions = [Condition.new]
|
query_conditions = [Condition.new]
|
||||||
in_phrase = false
|
in_phrase = false
|
||||||
query.each_char do |c|
|
query.each_char do |c|
|
||||||
|
|
|
@ -147,5 +147,14 @@ describe Item do
|
||||||
['One two four', 'Zero one']
|
['One two four', 'Zero one']
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
specify "should return raise exception for a query with no conditions" do
|
||||||
|
Factory.create :item
|
||||||
|
[
|
||||||
|
lambda { Item.search('').all },
|
||||||
|
lambda { Item.search(nil).all },
|
||||||
|
lambda { Item.search(' ').all }
|
||||||
|
].each { |l| l.should raise_error(ArgumentError) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue