is:pb filter for deluxe paint brush items
This commit is contained in:
parent
9e24def781
commit
c93066e679
2 changed files with 29 additions and 3 deletions
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue