Sha256: 3bc20164d1541f71f44ddf1f976c6c6f27f4d9817104365d74a8e0584aa0f7d3

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

require 'spec_helper'

module Spree
  describe Api::V1::InventoryUnitsController do
    render_views

    before do
      stub_authentication!
      @inventory_unit = create(:inventory_unit)
    end

    it "gets an inventory unit" do
      api_get :show, :id => @inventory_unit.id
      json_response['inventory_unit']['state'].should eq @inventory_unit.state
    end

    it "updates an inventory unit (only shipment is accessable by default)" do
      api_put :update, :id => @inventory_unit.id,
                       :inventory_unit => { :shipment => nil }
      json_response['inventory_unit']['shipment_id'].should be_nil
    end

    context 'fires state event' do
      it 'if supplied with :fire param' do
        api_put :update, :id => @inventory_unit.id,
                         :fire => 'ship',
                         :inventory_unit => { :shipment => nil }

        json_response['inventory_unit']['state'].should eq 'shipped'
      end

      it 'and returns exception if cannot fire' do
        api_put :update, :id => @inventory_unit.id,
                         :fire => 'return'
        json_response['exception'].should match /cannot transition to return/
      end

      it 'and returns exception bad state' do
        api_put :update, :id => @inventory_unit.id,
                         :fire => 'bad'
        json_response['exception'].should match /cannot transition to bad/
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spree_api-1.2.5 spec/controllers/spree/api/v1/inventory_units_controller_spec.rb
spree_api-1.2.4 spec/controllers/spree/api/v1/inventory_units_controller_spec.rb
spree_api-1.2.3 spec/controllers/spree/api/v1/inventory_units_controller_spec.rb