From fd61838946db3a291be6788fa39ca3f38f0440f1 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sat, 15 May 2010 18:23:23 -0400 Subject: [PATCH] add error for invalid species in search --- app/models/item.rb | 4 +++- spec/models/item_spec.rb | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) 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