Sha256: fb736dd9ce02a96d1112c21c9d28773985552aa4bbc1a2c41930312e11d7b5ba

Contents?: true

Size: 1.04 KB

Versions: 4

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

module Spree
  describe OrderContents do
    subject { described_class.new(order) }

    let!(:store) { create :store }
    let(:order) { Order.create }

    let(:guitar) { create(:variant) }
    let(:bass) { create(:variant) }

    let(:bundle) { create(:product) }

    before { bundle.parts.push [guitar, bass] }

    context "same variant within bundle and as regular product" do
      let!(:guitar_item) { subject.add(guitar, 3) }
      let!(:bundle_item) { subject.add(bundle.master, 5) }

      it "destroys the variant as regular product only" do
        subject.remove(guitar, 3)
        expect(order.reload.line_items.to_a).to eq [bundle_item]
      end

      context "completed order" do
        before do
          order.create_proposed_shipments
          order.touch :completed_at
        end

        it "destroys accurate number of inventory units" do
          expect { subject.remove(guitar, 3) }.
          to change(InventoryUnit, :count).by(-3)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solidus_product_assembly-1.4.0 spec/models/spree/order_contents_spec.rb
solidus_product_assembly-1.3.0 spec/models/spree/order_contents_spec.rb
solidus_product_assembly-1.2.0 spec/models/spree/order_contents_spec.rb
solidus_product_assembly-1.1.0 spec/models/spree/order_contents_spec.rb