Sha256: b06d372f3af0f85d8684bb2f3f333396ab42f196f0b86dd7524e1558123afc7b

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

require 'spec_helper'

module Spree
  module Stock
    describe AvailabilityValidator, type: :model do
      let!(:line_item) { double(quantity: 5, variant_id: 1, variant: double.as_null_object, errors: double('errors'), inventory_units: []) }

      subject { described_class.new }

      it 'should be valid when supply is sufficient' do
        allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: true)
        expect(line_item).not_to receive(:errors)
        subject.validate(line_item)
      end

      it 'should be invalid when supply is insufficent' do
        allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: false)
        expect(line_item.errors).to receive(:[]).with(:quantity).and_return []
        subject.validate(line_item)
      end

      it 'should consider existing inventory_units sufficient' do
        allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: false)
        expect(line_item).not_to receive(:errors)
        allow(line_item).to receive_messages(inventory_units: [double] * 5)
        subject.validate(line_item)
      end

      it 'should be valid when the quantity is zero' do
        expect(line_item).to receive(:quantity).and_return(0)
        expect(line_item.errors).to_not receive(:[]).with(:quantity)
        subject.validate(line_item)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_core-3.2.1 spec/models/spree/stock/availability_validator_spec.rb
spree_core-3.2.0 spec/models/spree/stock/availability_validator_spec.rb
spree_core-3.2.0.rc3 spec/models/spree/stock/availability_validator_spec.rb
spree_core-3.2.0.rc2 spec/models/spree/stock/availability_validator_spec.rb
spree_core-3.2.0.rc1 spec/models/spree/stock/availability_validator_spec.rb