From c93066e679c8f4f8cf15005dfb41b744858f06b1 Mon Sep 17 00:00:00 2001 From: Matchu Date: Sun, 3 Oct 2010 20:14:48 -0400 Subject: [PATCH] is:pb filter for deluxe paint brush items --- app/models/item.rb | 16 +++++++++++++--- spec/models/item_spec.rb | 16 ++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/app/models/item.rb b/app/models/item.rb index f158dd0c..34385c20 100644 --- a/app/models/item.rb +++ b/app/models/item.rb @@ -4,6 +4,7 @@ class Item < ActiveRecord::Base SwfAssetType = 'object' NCRarities = [0, 500] + PaintbrushSetDescription = 'This item is part of a deluxe paint brush set!' set_table_name 'objects' # Neo & PHP Impress call them objects, but the class name is a conflict (duh!) set_inheritance_column 'inheritance_type' # PHP Impress used "type" to describe category @@ -124,9 +125,18 @@ class Item < ActiveRecord::Base arel_table[:description].matches("%#{description}%") end - search_filter :is do |is_what| - raise ArgumentError, "We don't know how an item can be \"#{is_what}\". Did you mean is:nc?" unless is_what == 'nc' - arel_table[:rarity_index].in(NCRarities) + ADJECTIVE_FILTERS = { + 'nc' => arel_table[:rarity_index].in(NCRarities), + 'pb' => arel_table[:description].eq(PaintbrushSetDescription) + } + search_filter :is do |adjective| + filter = ADJECTIVE_FILTERS[adjective] + unless filter + raise ArgumentError, + "We don't know how an item can be \"#{adjective}\". " + + "Did you mean is:nc or is:pb?" + end + filter end search_filter :only do |species_name| diff --git a/spec/models/item_spec.rb b/spec/models/item_spec.rb index dc55883d..dc7a5787 100644 --- a/spec/models/item_spec.rb +++ b/spec/models/item_spec.rb @@ -169,8 +169,24 @@ describe Item do Item.search('-is:nc').map(&:name).should == ['not mall', 'also not mall'] end + specify "should search by is:pb" do + descriptions_by_name = { + 'Aisha Collar' => 'This item is part of a deluxe paint brush set!', + 'Christmas Buzz Hat' => 'This item is part of a deluxe paint brush set!', + 'Blue Hat' => 'This item is a trick and is NOT part of a deluxe paint brush set!', + 'Green Hat' => 'This hat is green.' + } + descriptions_by_name.each do |name, description| + Factory.create :item, :name => name, :description => description + end + Item.search('is:pb').map(&:name).should == ['Aisha Collar', 'Christmas Buzz Hat'] + Item.search('-is:pb').map(&:name).should == ['Blue Hat', 'Green Hat'] + + end + specify "is:[not 'nc' or 'pb'] should throw ArgumentError" do lambda { Item.search('is:nc') }.should_not raise_error(ArgumentError) + lambda { Item.search('is:pb') }.should_not raise_error(ArgumentError) lambda { Item.search('is:awesome') }.should raise_error(ArgumentError) end