Sha256: 12b2451a2fd7c66bbf50790221645cc9c2f21389c2109fd6f0ed05bf58ad6cc3

Contents?: true

Size: 1.35 KB

Versions: 16

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

16 entries across 16 versions & 1 rubygems

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