Permalink
Browse files

Add API calls to make shipments ready and to actually ship them

  • Loading branch information...
radar committed Apr 18, 2012
1 parent 8515192 commit e933f36ca7a014c1e75d820dd80caa3ba6cc3534
@@ -0,0 +1,31 @@
module Spree
module Api
module V1
class ShipmentsController < BaseController
before_filter :find_order
before_filter :find_and_update_shipment, :only => [:ship, :ready]
def ready
@shipment.ready!
render :show
end
def ship
@shipment.ship!
render :show
end
private
def find_order
@order = Order.find_by_number!(params[:order_id])
end
def find_and_update_shipment
@shipment = @order.shipments.find_by_number!(params[:id])
@shipment.update_attributes(params[:shipment])
end
end
end
end
end
@@ -47,6 +47,10 @@ def payment_attributes
def payment_method_attributes
[:id, :name, :description]
end
def shipment_attributes
[:id, :tracking, :number, :cost, :shipped_at, :state]
end
end
end
end
@@ -0,0 +1,2 @@
object @shipment
attributes *shipment_attributes
View
@@ -29,6 +29,13 @@
put :credit
end
end
resources :shipments do
member do
put :ready
put :ship
end
end
end
resources :countries, :only => [:index, :show]
@@ -0,0 +1,29 @@
require 'spec_helper'
describe Spree::Api::V1::ShipmentsController do
let!(:shipment) { Factory(:shipment) }
let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at] }
before do
shipment.order.payment_state == 'paid'
stub_authentication!
end
context "working with a shipment" do
let!(:resource_scoping) { { :order_id => shipment.order.to_param, :id => shipment.to_param } }
it "can make a shipment ready" do
api_put :ready
json_response.should have_attributes(attributes)
json_response["shipment"]["state"].should == "ready"
end
it "can transition a shipment from ready to ship" do
shipment.ready!
shipment.save!
api_put :ship, :order_id => shipment.order.to_param, :id => shipment.to_param, :shipment => { :tracking => "123123" }
json_response.should have_attributes(attributes)
json_response["shipment"]["state"].should == "ship"
end
end
end

0 comments on commit e933f36

Please sign in to comment.