Skip to content

Commit

Permalink
support order field search.
Browse files Browse the repository at this point in the history
  • Loading branch information
saberma committed Oct 4, 2012
1 parent 25d4d53 commit c6a5466
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/api/v1/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
module Api::V1
class OrdersController < AppController
doorkeeper_for :index, :show, scopes: [:read_orders, :write_orders], unless: lambda { @api_client }
FIELDS = [:financial_status, :fulfillment_status]

def index
@orders = shop.orders.page(page).per(per_page)
conditions = {}
FIELDS.each do |field|
conditions[field] = params[field] unless params[field].blank?
end
@orders = shop.orders.where(conditions).page(page).per(per_page)
end

def show
Expand Down
26 changes: 26 additions & 0 deletions spec/controllers/api/v1/orders_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,32 @@
json.size.should eql 0
end

context 'search' do

context '#financial_status' do

it 'should be success' do
get :index, financial_status: 'pending', format: :json, access_token: token.token
JSON(response.body)['orders'].size.should eql 1
get :index, financial_status: 'paid', format: :json, access_token: token.token
JSON(response.body)['orders'].size.should eql 0
end

end

context '#fulfillment_status' do

it 'should be success' do
get :index, fulfillment_status: 'unshipped', format: :json, access_token: token.token
JSON(response.body)['orders'].size.should eql 0
get :index, fulfillment_status: 'fulfilled', format: :json, access_token: token.token
JSON(response.body)['orders'].size.should eql 1
end

end

end

end

context 'show' do
Expand Down

0 comments on commit c6a5466

Please sign in to comment.