Skip to content

Commit

Permalink
Fixed Spree::Api::ProductsController#index to accept multiple ids
Browse files Browse the repository at this point in the history
  • Loading branch information
t-k authored and radar committed Oct 22, 2013
1 parent 4e8ba75 commit 8cafc82
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions api/app/controllers/spree/api/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ProductsController < Spree::Api::BaseController

def index
if params[:ids]
@products = product_scope.where(:id => params[:ids])
@products = product_scope.where(:id => params[:ids].split(","))
else
@products = product_scope.ransack(params[:q]).result
end
Expand Down Expand Up @@ -35,7 +35,7 @@ def create
@product.permalink = nil
retry
end
end
end

def update
@product = find_product(params[:id])
Expand Down
11 changes: 11 additions & 0 deletions api/spec/controllers/spree/api/products_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ module Spree
json_response["per_page"].should == Kaminari.config.default_per_page
end

it "retrieves a list of products by ids string" do
second_product = create(:product)
api_get :index, :ids => [product.id, second_product.id].join(",")
json_response["products"].first.should have_attributes(attributes)
json_response["products"][1].should have_attributes(attributes)
json_response["total_count"].should == 2
json_response["current_page"].should == 1
json_response["pages"].should == 1
json_response["per_page"].should == Kaminari.config.default_per_page
end

it "does not return inactive products when queried by ids" do
api_get :index, :ids => [inactive_product.id]
json_response["count"].should == 0
Expand Down

0 comments on commit 8cafc82

Please sign in to comment.