Skip to content

armgit / spree

Public Imported from GitHub
0

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.

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.rb
index 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 do
unit.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 #3066
diff --git a/spree/core/spec/models/spree/line_item_spec.rb b/spree/core/spec/models/spree/line_item_spec.rb
index 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 do
expect(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' do
second_licence = create(:product, delivery_profile: digital_profile, store: store).default_variant
second_licence.update!(track_inventory: true)
stock_level = second_licence.stock_levels.first
@@ -172,7 +174,9 @@ describe Spree::LineItem, type: :model do
expect {
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)
end
end
diff --git a/spree/core/spec/models/spree/product_preorder_spec.rb b/spree/core/spec/models/spree/product_preorder_spec.rb
index 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 do
end
it '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 false
expect(variant.purchasable?).to be false
end
diff --git a/spree/core/spec/models/spree/shipment_spec.rb b/spree/core/spec/models/spree/shipment_spec.rb
index 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 do
expect(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' do
allow(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_cancel
end
@@ -707,20 +707,20 @@ describe Spree::Shipment, type: :model do
expect(shipment.reload.status).to eq 'unfulfilled'
end
- it 'unstocks them items' do
+ it 're-promises the items' do
allow(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_resume
end
context 'for a shipment item that does not track inventory' do
before { variant.update(track_inventory: false) }
- it 'skips unstocking the shipment item' do
+ it 'skips allocating the shipment item' do
allow(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_resume
end
end