Sha256: 62f34aecc02007443472246bd88f9991934c6169bcce959fc0de33f6b3c46223

Contents?: true

Size: 1.63 KB

Versions: 31

Compression:

Stored size: 1.63 KB

Contents

require 'spec_helper'

module Spree
  module Stock
    describe Splitter::ShippingCategory, type: :model do
      let(:order) { create(:order_with_line_items, line_items_count: 1) }
      let(:line_item) { order.line_items.first }
      let(:variant1) { build(:variant) }
      let(:variant2) { build(:variant) }
      let(:shipping_category_1) { create(:shipping_category, name: 'A') }
      let(:shipping_category_2) { create(:shipping_category, name: 'B') }

      def inventory_unit1
        build(:inventory_unit, variant: variant1, order: order, line_item: line_item).tap do |inventory_unit|
          inventory_unit.variant.product.shipping_category = shipping_category_1
        end
      end

      def inventory_unit2
        build(:inventory_unit, variant: variant2, order: order, line_item: line_item).tap do |inventory_unit|
          inventory_unit.variant.product.shipping_category = shipping_category_2
        end
      end

      let(:packer) { build(:stock_packer) }

      subject { described_class.new(packer) }

      it 'splits each package by shipping category' do
        package1 = Package.new(packer.stock_location)
        4.times { package1.add inventory_unit1 }
        8.times { package1.add inventory_unit2 }

        package2 = Package.new(packer.stock_location)
        6.times { package2.add inventory_unit1 }
        9.times { package2.add inventory_unit2, :backordered }

        packages = subject.split([package1, package2])
        expect(packages[0].quantity).to eq 4
        expect(packages[1].quantity).to eq 8
        expect(packages[2].quantity).to eq 6
        expect(packages[3].quantity).to eq 9
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

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