Sha256: a223f4fa16d8d5ac7ab42aec95c337cdde80211a4e321442cbe98459e3dd5203

Contents?: true

Size: 1.51 KB

Versions: 25

Compression:

Stored size: 1.51 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!
      let(:variant) { create(:variant) }

      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" do
        api_put :update, :id => @inventory_unit.id,
                         :inventory_unit => { variant_id: variant.id }
        expect(json_response['variant_id']).to eq variant.id
      end

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

          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

25 entries across 25 versions & 1 rubygems

Version Path
solidus_api-1.2.3 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.4 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.0.7 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.0.6 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.2.2 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.2.1 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.3 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.0.5 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.2.0 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.2.0.rc2 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.0.4 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.2 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.2.0.rc1 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.2.0.beta1 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.0.3 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.1 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.0 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.0.pre2 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.0.pre1 spec/controllers/spree/api/inventory_units_controller_spec.rb
solidus_api-1.1.0.beta1 spec/controllers/spree/api/inventory_units_controller_spec.rb