Permalink
Browse files

Add searching ability to products API

  • Loading branch information...
radar committed Apr 11, 2012
1 parent e55d3b1 commit 024b22a56929468548eca795407d6b2001a836de
@@ -6,6 +6,11 @@ def index
@products = product_scope.page(params[:page])
end
def search
@products = product_scope.search(params[:q]).result.page(params[:page])
render :index
end
def show
@product = find_product(params[:id])
end
View
@@ -2,6 +2,10 @@
namespace :api do
scope :module => :v1 do
resources :products do
collection do
get :search
end
resources :variants
resources :images
end
@@ -39,6 +39,13 @@ module Spree
end
end
it "can search for products" do
Factory(:product, :name => "The best product in the world")
api_get :search, :q => { :name_cont => "best" }
json_response["products"].first.should have_attributes(attributes)
json_response["count"].should == 1
end
it "gets a single product" do
product.master.images.create!(:attachment => image("thinking-cat.jpg"))
api_get :show, :id => product.to_param

0 comments on commit 024b22a

Please sign in to comment.