Sha256: 9ab5051eb843ea92a40218058f5c58ade361232655d304b470ffd1d6afa16bff

Contents?: true

Size: 1.55 KB

Versions: 34

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'rails_helper'

RSpec.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

34 entries across 34 versions & 2 rubygems

Version Path
solidus_core-2.8.6 spec/models/spree/stock_movement_spec.rb
solidus_core-2.6.6 spec/models/spree/stock_movement_spec.rb
solidus_core-2.7.4 spec/models/spree/stock_movement_spec.rb
solidus_core-2.8.5 spec/models/spree/stock_movement_spec.rb
solidus_core-2.7.3 spec/models/spree/stock_movement_spec.rb
solidus_core-2.6.5 spec/models/spree/stock_movement_spec.rb
solidus_core-2.8.4 spec/models/spree/stock_movement_spec.rb
solidus_core-2.8.3 spec/models/spree/stock_movement_spec.rb
solidus_core-2.7.2 spec/models/spree/stock_movement_spec.rb
solidus_core-2.6.4 spec/models/spree/stock_movement_spec.rb
solidus_core-2.8.2 spec/models/spree/stock_movement_spec.rb
solidus_core-2.8.1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.6.3 spec/models/spree/stock_movement_spec.rb
solidus_core-2.8.0 spec/models/spree/stock_movement_spec.rb
solidus_core-2.7.1 spec/models/spree/stock_movement_spec.rb
solidus_core-2.6.2 spec/models/spree/stock_movement_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.14 spec/models/spree/stock_movement_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.13 spec/models/spree/stock_movement_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.12 spec/models/spree/stock_movement_spec.rb
solidus_core_devise_token_auth-2.8.0.alpha.11 spec/models/spree/stock_movement_spec.rb