diff --git a/api/app/controllers/spree/api/option_types_controller.rb b/api/app/controllers/spree/api/option_types_controller.rb index cc0a4d450c7..fc28b95a6d8 100644 --- a/api/app/controllers/spree/api/option_types_controller.rb +++ b/api/app/controllers/spree/api/option_types_controller.rb @@ -2,7 +2,11 @@ module Spree module Api class OptionTypesController < Spree::Api::BaseController def index - @option_types = Spree::OptionType.all + if params[:ids] + @option_types = Spree::OptionType.where(:id => params[:ids]) + else + @option_types = Spree::OptionType.scoped.ransack(params[:q]).result + end respond_with(@option_types) end diff --git a/api/spec/controllers/spree/api/option_types_controller_spec.rb b/api/spec/controllers/spree/api/option_types_controller_spec.rb index 99c1b6569b2..13cbed70faf 100644 --- a/api/spec/controllers/spree/api/option_types_controller_spec.rb +++ b/api/spec/controllers/spree/api/option_types_controller_spec.rb @@ -27,6 +27,22 @@ def check_option_values(option_values) check_option_values(option_types.first["option_values"]) end + it "can search for an option type" do + Factory(:option_type, :name => "buzz") + api_get :index, :q => { :name_cont => option_type.name } + option_types = json_response["option_types"] + option_types.count.should == 1 + option_types.first.should have_attributes(attributes) + end + + it "can retreive a list of option types" do + option_type_1 = Factory(:option_type) + option_type_2 = Factory(:option_type) + api_get :index, :ids => [option_type, option_type_1] + option_types = json_response["option_types"] + option_types.count.should == 2 + end + it "can list a single option type" do api_get :show, :id => option_type.id json_response.should have_attributes(attributes)