diff --git a/app/models/item.rb b/app/models/item.rb index 77a7584c..a89e731e 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -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, diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index 93de011b..34c4af6e 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -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