add error for invalid species in search

This commit is contained in:
Emi Matchu 2010-05-15 18:23:23 -04:00
parent 1de7df3c4a
commit fd61838946
2 changed files with 7 additions and 1 deletions

View file

@ -58,7 +58,9 @@ class Item < ActiveRecord::Base
items = Table(:objects)
if @property == 'species'
species = Species.find_by_name(self)
# TODO: add a many-to-many table to handle this relationship
raise ArgumentError, "Species \"#{self.humanize}\" does not exist" unless species
# TODO: add a many-to-many table to handle this relationship, if
# performance becomes an issue
ids = items[:species_support_ids]
condition = ids.eq('').or(ids.matches_any(
species.id,

View file

@ -168,5 +168,9 @@ describe Item do
specify "should not be able to search other attributes thru filters" do
lambda { Item.search('id:1').all }.should raise_error(ArgumentError)
end
specify "should raise exception if species not found" do
lambda { Item.search('species:hurfdurfdurf').all }.should raise_error(ArgumentError)
end
end
end