Sha256: ae14657ca556447cafd61ca070ef59357d6480a259e60892e1cddf90b2b40e11

Contents?: true

Size: 940 Bytes

Versions: 3

Compression:

Stored size: 940 Bytes

Contents

require 'spec_helper'

module Spree
  describe InventoryUnit do
    let!(:order) { create(:order_with_line_items) }
    let(:line_item) { order.line_items.first }
    let(:product) { line_item.product }

    subject { InventoryUnit.create(line_item: line_item, variant: line_item.variant, order: order) }

    context 'if the unit is not part of an assembly' do      
      it 'it will return the percentage of a line item' do
        expect(subject.percentage_of_line_item).to eql(BigDecimal.new(1))
      end
    end

    context 'if part of an assembly' do
      let(:parts) { (1..2).map { create(:variant) } }

      before do
        product.parts << parts
        order.create_proposed_shipments
        order.finalize!
      end

      it 'it will return the percentage of a line item' do
        subject.line_item = line_item
      	expect(subject.percentage_of_line_item).to eql(BigDecimal.new(0.5, 2))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
solidus_product_bundle-1.0.1 spec/models/spree/inventory_unit_spec.rb
solidus_product_bundle-1.0.0 spec/models/spree/inventory_unit_spec.rb
solidus_product_assembly-1.0.0 spec/models/spree/inventory_unit_spec.rb