Sha256: ea65669713ae3952223e1513f77f39e90d963ff28d899ad389c020620156c7a4

Contents?: true

Size: 1.5 KB

Versions: 36

Compression:

Stored size: 1.5 KB

Contents

require 'spec_helper'

module Spree
  describe Api::InventoryUnitsController, :type => :controller do
    render_views

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

    context "as an admin" do
      sign_in_as_admin!

      it "gets an inventory unit" do
        api_get :show, :id => @inventory_unit.id
        expect(json_response['state']).to 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 }
        expect(json_response['shipment_id']).to 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 }

          expect(json_response['state']).to eq 'shipped'
        end

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

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

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
spree_api-3.0.10 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.9 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.8 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.7 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.6.1 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.6 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.5 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.4 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.4.10 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.3.13 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.3 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.4.9 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.3.12 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.2 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.4.8 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.3.11 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.1 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.4.7 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-2.3.10 spec/controllers/spree/api/inventory_units_controller_spec.rb
spree_api-3.0.0 spec/controllers/spree/api/inventory_units_controller_spec.rb