Skip to content

Commit

Permalink
[api] Add ransacking + 'ids' support to option types controller
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Dec 3, 2012
1 parent 3f0b6de commit cff0a3c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/app/controllers/spree/api/option_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions api/spec/controllers/spree/api/option_types_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit cff0a3c

Please sign in to comment.