From 8cafc827107a21d0cf7e28f5f9d75a55d7607c60 Mon Sep 17 00:00:00 2001 From: Tatsuo Kaniwa Date: Fri, 18 Oct 2013 11:52:51 +0900 Subject: [PATCH] Fixed Spree::Api::ProductsController#index to accept multiple ids Fixes #3886 --- api/app/controllers/spree/api/products_controller.rb | 4 ++-- .../controllers/spree/api/products_controller_spec.rb | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/api/app/controllers/spree/api/products_controller.rb b/api/app/controllers/spree/api/products_controller.rb index 86e62ee4167..bde6af9adf3 100644 --- a/api/app/controllers/spree/api/products_controller.rb +++ b/api/app/controllers/spree/api/products_controller.rb @@ -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 @@ -35,7 +35,7 @@ def create @product.permalink = nil retry end - end + end def update @product = find_product(params[:id]) diff --git a/api/spec/controllers/spree/api/products_controller_spec.rb b/api/spec/controllers/spree/api/products_controller_spec.rb index 2ec09982db6..7e6ab34c177 100644 --- a/api/spec/controllers/spree/api/products_controller_spec.rb +++ b/api/spec/controllers/spree/api/products_controller_spec.rb @@ -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