Sha256: 11c68b58bc90f0bc54ca817d3c7b60e029718960f31d4ae29f69beef62eaf8c4

Contents?: true

Size: 1.51 KB

Versions: 32

Compression:

Stored size: 1.51 KB

Contents

require 'spec_helper'

describe Spree::StockMovement, type: :model do
  let(:stock_location) { create(:stock_location_with_items) }
  let(:stock_item) { stock_location.stock_items.order(:id).first }
  subject { build(:stock_movement, stock_item: stock_item) }

  it 'should belong to a stock item' do
    expect(subject).to respond_to(:stock_item)
  end

  it 'is readonly unless new' do
    subject.save
    expect {
      subject.save
    }.to raise_error(ActiveRecord::ReadOnlyRecord)
  end

  it 'does not update count on hand when track inventory levels is false' do
    Spree::Config[:track_inventory_levels] = false
    subject.quantity = 1
    subject.save
    stock_item.reload
    expect(stock_item.count_on_hand).to eq(10)
  end

  it 'does not update count on hand when variant inventory tracking is off' do
    stock_item.variant.track_inventory = false
    subject.quantity = 1
    subject.save
    stock_item.reload
    expect(stock_item.count_on_hand).to eq(10)
  end

  context "when quantity is negative" do
    context "after save" do
      it "should decrement the stock item count on hand" do
        subject.quantity = -1
        subject.save
        stock_item.reload
        expect(stock_item.count_on_hand).to eq(9)
      end
    end
  end

  context "when quantity is positive" do
    context "after save" do
      it "should increment the stock item count on hand" do
        subject.quantity = 1
        subject.save
        stock_item.reload
        expect(stock_item.count_on_hand).to eq(11)
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
solidus_core-2.3.1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.2.2 spec/models/spree/stock_movement_spec.rb
solidus_core-2.1.1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.0.3 spec/models/spree/stock_movement_spec.rb
solidus_core-1.4.2 spec/models/spree/stock_movement_spec.rb
solidus_core-1.3.2 spec/models/spree/stock_movement_spec.rb
solidus_core-2.3.0 spec/models/spree/stock_movement_spec.rb
solidus_core-2.3.0.rc3 spec/models/spree/stock_movement_spec.rb
solidus_core-2.3.0.rc2 spec/models/spree/stock_movement_spec.rb
solidus_core-2.3.0.rc1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.3.0.beta1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.0.2 spec/models/spree/stock_movement_spec.rb
solidus_core-1.4.1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.2.1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.2.0 spec/models/spree/stock_movement_spec.rb
solidus_core-2.2.0.rc1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.2.0.beta1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.1.0 spec/models/spree/stock_movement_spec.rb
solidus_core-2.1.0.rc1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.0.1 spec/models/spree/stock_movement_spec.rb