forked from OpenNeo/impress
add error for invalid species in search
This commit is contained in:
parent
1de7df3c4a
commit
fd61838946
2 changed files with 7 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue