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.

Stage a real 5.6 shelf in the migration regression fixture

Łukasz Adamczykcae6e1a78835
diff --git a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb
index a1f27760a6..ae098609ee 100644
--- a/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb
+++ b/spree/core/spec/lib/tasks/six_zero_data_migrations_spec.rb
@@ -862,25 +862,34 @@ describe '6.0 data migration tasks' do
# whose units left the shelf at placement. A real 5.6 row carries no kind
# and no allocation, so this strips what modern placement wrote and leaves
# only the legacy departure behind.
- def legacy_placement!
+ # +shelf+ is what the warehouse physically holds. Under 5.6 placement had
+ # already taken the ordered units off it, so the stored count starts that
+ # much lower and the migration's job is to put them back. Writing the
+ # count by hand is what makes this a 5.6 fixture: a kind-less movement
+ # moves no counter, so inserting the legacy row alone would leave the
+ # shelf at its post-migration value and hide an inflated count.
+ def legacy_placement!(shelf: 10)
Spree::StockMovement.unscoped.where(stock_level_id: level.id).delete_all
- level.update_columns(allocated_count: 0)
+ level.update_columns(count_on_hand: shelf - quantity, allocated_count: 0)
legacy_movement(-quantity, originator_type: 'Spree::Fulfillment', originator_id: fulfillment.id, level: level)
end
context 'when the fulfillment carries a legacy placement row' do
- it 'leaves it holding its promise, with availability unchanged' do
- legacy_placement!
- shelf_before = level.reload.count_on_hand
- available_before = level.available_count
+ # Absolute counts, not deltas: the units are back on the shelf where a
+ # picker would find them, promised to this fulfillment, and what a
+ # customer can still buy is what it was before the upgrade.
+ it 'leaves it holding its promise, with the shelf restored and availability unchanged' do
+ legacy_placement!(shelf: 10)
+ available_before = level.reload.available_count
run_task('spree:migrate_stock_movements_to_typed_rows')
level.reload
expect(fulfillment.reload.allocated_quantities[reconciled_variant.id]).to eq(quantity)
- expect(level.count_on_hand).to eq(shelf_before + quantity)
+ expect(level.count_on_hand).to eq(10)
expect(level.allocated_count).to eq(quantity)
expect(level.available_count).to eq(available_before)
+ expect(level.available_count).to eq(10 - quantity)
end
# Typing the placement row as a departure used to retire the promise, so