From b76d16a90e57e08943a088d467c5208c022e89a1 Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 23 Feb 2023 17:31:43 +0100 Subject: [PATCH] Ensure target shipments are evaluated in order of creation This solves a long standing flakey spec which was uncovering an actual issue. --- core/app/models/spree/order_inventory.rb | 2 +- core/spec/models/spree/order_inventory_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/app/models/spree/order_inventory.rb b/core/app/models/spree/order_inventory.rb index 7e4425a5852..a0521b8f8b5 100644 --- a/core/app/models/spree/order_inventory.rb +++ b/core/app/models/spree/order_inventory.rb @@ -57,7 +57,7 @@ def remove(quantity, shipment = nil) # first unshipped that's leaving from a stock_location that stocks this variant, with availability check # first unshipped that's leaving from a stock_location that stocks this variant, without availability check def determine_target_shipment(quantity) - potential_shipments = order.shipments.select(&:ready_or_pending?) + potential_shipments = order.shipments.order(:created_at, :id).select(&:ready_or_pending?) potential_shipments.detect do |shipment| shipment.include?(variant) diff --git a/core/spec/models/spree/order_inventory_spec.rb b/core/spec/models/spree/order_inventory_spec.rb index f82ca4797ca..85ea8623244 100644 --- a/core/spec/models/spree/order_inventory_spec.rb +++ b/core/spec/models/spree/order_inventory_spec.rb @@ -171,7 +171,7 @@ end context 'when there is not enough availability at any stock location' do - it 'falls-back selecting first non-shipped shipment that leaves from same stock_location', :flaky do + it 'falls-back selecting first non-shipped shipment that leaves from same stock_location' do shipment = subject.send(:determine_target_shipment, 1) shipment.reload