item search throws exception if not given query

This commit is contained in:
Emi Matchu 2010-05-15 13:28:34 -04:00
parent 5b86e640b0
commit ae09fe0515
2 changed files with 11 additions and 0 deletions

View file

@ -14,6 +14,8 @@ class Item < ActiveRecord::Base
end
def self.search(query)
query = query.strip if query
raise ArgumentError, "Please provide a search query" if query.blank?
query_conditions = [Condition.new]
in_phrase = false
query.each_char do |c|

View file

@ -147,5 +147,14 @@ describe Item do
['One two four', 'Zero one']
]
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