Sha256: 7fd441e3d14049fe2b3305696441e440eb7a48d327b0ce796c9a843eef277b02

Contents?: true

Size: 1.52 KB

Versions: 16

Compression:

Stored size: 1.52 KB

Contents

require 'spec_helper'

module Spree
  describe StockTransfer, :type => :model do
    let(:destination_location) { create(:stock_location_with_items) }
    let(:source_location) { create(:stock_location_with_items) }
    let(:stock_item) { source_location.stock_items.order(:id).first }
    let(:variant) { stock_item.variant }

    subject { StockTransfer.create(reference: 'PO123') }

    describe '#reference' do
      subject { super().reference }
      it { is_expected.to eq 'PO123' }
    end

    describe '#to_param' do
      subject { super().to_param }
      it { is_expected.to match /T\d+/ }
    end

    it 'transfers variants between 2 locations' do
      variants = { variant => 5 }

      subject.transfer(source_location,
                       destination_location,
                       variants)

      expect(source_location.count_on_hand(variant)).to eq 5
      expect(destination_location.count_on_hand(variant)).to eq 5

      expect(subject.source_location).to eq source_location
      expect(subject.destination_location).to eq destination_location

      expect(subject.source_movements.first.quantity).to eq -5
      expect(subject.destination_movements.first.quantity).to eq 5
    end

    it 'receive new inventory (from a vendor)' do
      variants = { variant => 5 }

      subject.receive(destination_location, variants)

      expect(destination_location.count_on_hand(variant)).to eq 5

      expect(subject.source_location).to be_nil
      expect(subject.destination_location).to eq destination_location
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
spree_core-3.1.5 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.4 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.3 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.2 spec/models/spree/stock_transfer_spec.rb
spree_core-3.0.10 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.1 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.0 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.0.rc4 spec/models/spree/stock_transfer_spec.rb
spree_core-3.0.9 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.0.rc3 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.0.rc2 spec/models/spree/stock_transfer_spec.rb
spree_core-3.1.0.rc1 spec/models/spree/stock_transfer_spec.rb
spree_core-3.0.8 spec/models/spree/stock_transfer_spec.rb
spree_core-3.0.7 spec/models/spree/stock_transfer_spec.rb
spree_core-3.0.6.1 spec/models/spree/stock_transfer_spec.rb
spree_core-3.0.6 spec/models/spree/stock_transfer_spec.rb