Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Phase P2.7: Restate the remaining specs against the new stock semantics
Łukasz Adamczyk44399f7ad0f9
diff --git a/spree/core/spec/models/spree/inventory_unit_spec.rb b/spree/core/spec/models/spree/inventory_unit_spec.rbindex 08956214f9..36b8844b58 100644--- a/spree/core/spec/models/spree/inventory_unit_spec.rb+++ b/spree/core/spec/models/spree/inventory_unit_spec.rb@@ -56,8 +56,10 @@ describe Spree::InventoryUnit, type: :model dounit.tap(&:save!)end+ # A shelf below zero is legacy fixture state now — only a departure may+ # write one — so it is set on the column directly.before do- stock_level.set_count_on_hand(-2)+ stock_level.update_column(:count_on_hand, -2)end# Regression for #3066diff --git a/spree/core/spec/models/spree/line_item_spec.rb b/spree/core/spec/models/spree/line_item_spec.rbindex 0c7b3d9acf..ff34aaaa6e 100644--- a/spree/core/spec/models/spree/line_item_spec.rb+++ b/spree/core/spec/models/spree/line_item_spec.rb@@ -164,7 +164,9 @@ describe Spree::LineItem, type: :model doexpect(line_item.reload.inventory_units.sum(&:quantity)).to eq(2)end- it 'decrements stock for a tracked digital variant' do+ # Adding to a placed order promises stock rather than moving it; the+ # shelf empties when the parcel does.+ it 'allocates stock for a tracked digital variant' dosecond_licence = create(:product, delivery_profile: digital_profile, store: store).default_variantsecond_licence.update!(track_inventory: true)stock_level = second_licence.stock_levels.first@@ -172,7 +174,9 @@ describe Spree::LineItem, type: :model doexpect {create(:line_item, order: order, variant: second_licence, quantity: 2)- }.to change { stock_level.reload.count_on_hand }.from(5).to(3)+ }.to change { stock_level.reload.allocated_count }.from(0).to(2)++ expect(stock_level.reload.count_on_hand).to eq(5)endenddiff --git a/spree/core/spec/models/spree/product_preorder_spec.rb b/spree/core/spec/models/spree/product_preorder_spec.rbindex 074814938b..ba84353cd9 100644--- a/spree/core/spec/models/spree/product_preorder_spec.rb+++ b/spree/core/spec/models/spree/product_preorder_spec.rb@@ -96,7 +96,10 @@ RSpec.describe 'Pre-order', type: :model doendit 'is not purchasable once the limit is used up' do- stock_level.set_count_on_hand(-5) # 5 units already oversold+ # An oversell lives in allocated_count now, not in a negative shelf.+ # The signed arithmetic is identical: on hand minus allocated is -5+ # either way.+ stock_level.update_columns(count_on_hand: 0, allocated_count: 5)expect(quantifier.can_supply?(1)).to be falseexpect(variant.purchasable?).to be falseenddiff --git a/spree/core/spec/models/spree/shipment_spec.rb b/spree/core/spec/models/spree/shipment_spec.rbindex 46c48b8f61..be19176d25 100644--- a/spree/core/spec/models/spree/shipment_spec.rb+++ b/spree/core/spec/models/spree/shipment_spec.rb@@ -653,14 +653,14 @@ describe Spree::Shipment, type: :model doexpect(shipment.status).to eq 'canceled'end- # Restocking belongs to Spree::Fulfillments::Cancel now; the deprecated- # shell is all that survives on the model. Covered by+ # Withdrawing the promise belongs to Spree::Fulfillments::Cancel now; the+ # deprecated shell is all that survives on the model. Covered by# spec/workflows/spree/fulfillments/cancel_spec.rb.- it 'restocks the items through the deprecated shell' do+ it 'releases the items through the deprecated shell' doallow(shipment).to receive(:fulfillment_items).and_return([inventory_unit])allow(shipment).to receive(:provider).and_return(instance_double(Spree::FulfillmentProvider::Manual, cancel_fulfillment: true))shipment.stock_location = create(:stock_location)- expect(shipment.stock_location).to receive(:restock).with(variant, 1, shipment)+ expect(shipment.stock_location).to receive(:release).with(variant, 1, shipment)shipment.after_cancelend@@ -707,20 +707,20 @@ describe Spree::Shipment, type: :model doexpect(shipment.reload.status).to eq 'unfulfilled'end- it 'unstocks them items' do+ it 're-promises the items' doallow(shipment).to receive(:fulfillment_items).and_return([inventory_unit])shipment.stock_location = create(:stock_location)- expect(shipment.stock_location).to receive(:unstock).with(variant, 1, shipment)+ expect(shipment.stock_location).to receive(:allocate).with(variant, 1, shipment)shipment.after_resumeendcontext 'for a shipment item that does not track inventory' dobefore { variant.update(track_inventory: false) }- it 'skips unstocking the shipment item' do+ it 'skips allocating the shipment item' doallow(shipment).to receive(:fulfillment_items).and_return([inventory_unit])shipment.stock_location = create(:stock_location)- expect(shipment.stock_location).not_to receive(:unstock)+ expect(shipment.stock_location).not_to receive(:allocate)shipment.after_resumeendend