Sha256: f99ac180aba785e09fbeaa3ae14d2d0b4a706caf233c1e0f3e1788511a3e1226

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 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: []) }
      let(:inventory_unit) { double("InventoryUnit") }
      let(:inventory_units) { [inventory_unit] }

      subject { described_class.new }

      before do
        allow(inventory_unit).to receive_messages(quantity: 5)
      end

      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: inventory_units)
        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

1 entries across 1 versions & 1 rubygems

Version Path
spree_core-3.3.0.rc1 spec/models/spree/stock/availability_validator_spec.rb