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
Make the delivery-cost regression specs deterministic
Damian Legawiec7d373c12fc96
diff --git a/docs/plans/6.0-fulfillment-and-delivery.md b/docs/plans/6.0-fulfillment-and-delivery.mdindex 0b2a251c3e..4bce776d65 100644--- a/docs/plans/6.0-fulfillment-and-delivery.md+++ b/docs/plans/6.0-fulfillment-and-delivery.md@@ -4,7 +4,7 @@**Target:** Spree 6.0**Depends on:** `6.0-product-types.md` (`fulfillment_types` addendum 2026-07-27 — ProductType replaces ShippingCategory; **shipped**, including the `fulfillment_types` column), `6.0-cart-order-split.md` (where fulfillments/rates live pre-completion), `6.0-order-routing.md` (packages come from `for_allocation`), `6.0-normalize-state-to-status.md`. Coordinates with: `6.0-delivery-rate-provider.md` (owns `store_id` on DeliveryMethod; calculators stay per decisions.md 2026-07-27), `5.5-6.0-display-on-to-boolean.md` (`storefront_visible` — DeliveryMethod moved off the `Spree::DisplayOn` concern 2026-08-05), `6.0-multi-vendor-marketplace.md` (`vendor_id`, lifecycle events, `delivery_amount`). Gates: `6.0-6.1-split-adjustments.md` and `6.0-typed-stock-movements.md` are born with `fulfillment_id` — **this plan's Phase 1 must land before both**.**Author:** Damian + Claude-**Last updated:** 2026-08-05+**Last updated:** 2026-08-06## Summary@@ -17,7 +17,7 @@ Three changes in one:**Calculators are NOT touched by this plan.** The 2026-07-27 decision (decisions.md) keeps `ShippingCalculator` + `Calculator::Shipping::*`; rate estimation is the delivery-rate-provider plan's domain. **Zone replacement ships in 6.0 via `6.0-delivery-zones.md`** — this plan's Phase 1 births `spree_delivery_method_zones` pointing at `DeliveryZone` (born correct, never re-migrated).-## Implementation status (verified 2026-08-05 against `feat/fulfillment-delivery-rework`)+## Implementation status (verified 2026-08-06 against `feat/fulfillment-delivery-rework`)**Phases 1a, 1b, 2, 3, 4 and 5 are implemented.** Verified in code: the rename migrations (`20260728000004/5`) including every FK and the `orders` column pair; model renames with one-release deprecation shells (`Spree::Shipment`, `ShippingMethod`, `InventoryUnit`, `FulfilmentChanger` are constant aliases); `Package#eligible_delivery_methods` + `Stock::Splitter::FulfillmentType`; `ProductType#fulfillment_types` with registry-backed inclusion validation; all five providers plus `PickupPointProvider::Base`; the `Spree.fulfillment_types` / `Spree.fulfillment_providers` registries; lifecycle events with `shipment.*` dual-emit and `order.fulfilled` / `Order#fully_fulfilled?`; dual `cart_id`/`order_id` owner with exactly-one validation; `Estimator` location gating via `serves_location?`; pickup discovery endpoints and the `fulfillment_providers` discovery route; admin delivery-method and delivery-zone CRUD; `FulfillmentMailer` (with a `ShipmentMailer` shell); `return_items.fulfillment_item_id`; and both data rake tasks wired into the 5.6→6.0 upgrade manifest.diff --git a/spree/core/spec/models/spree/line_item_spec.rb b/spree/core/spec/models/spree/line_item_spec.rbindex 8dddb53386..3d5c320e3f 100644--- a/spree/core/spec/models/spree/line_item_spec.rb+++ b/spree/core/spec/models/spree/line_item_spec.rb@@ -617,6 +617,8 @@ describe Spree::LineItem, type: :model doendcontext 'when one fulfillment holds several of this line item units' do+ let(:line_item) { create(:line_item, quantity: 2) }+it 'counts that fulfillment once, not once per unit' dosecond_unit = create(:inventory_unit, line_item: line_item, variant: inventory_unit.variant)shipment.fulfillment_items << second_unit@@ -626,13 +628,20 @@ describe Spree::LineItem, type: :model doendcontext 'when a canceled fulfillment precedes an active one' do+ let(:line_item) { create(:line_item, quantity: 2) }++ # The canceled one must be visited first, otherwise a premature `return`+ # would reach the active cost anyway and the guard would look correct.it 'still charges the active fulfillment' doshipment.update_columns(cost: 10, status: 'canceled')active = create(:shipment, cost: 10, order: shipment.order, stock_location: shipment.stock_location)active.fulfillment_items << create(:inventory_unit, line_item: line_item, variant: inventory_unit.variant)- expect(line_item.reload.delivery_cost).to eq(10)+ line_item.reload+ expect(line_item.fulfillments.first).to eq(shipment)++ expect(line_item.delivery_cost).to eq(10)endendend