Fix Spree::Order::InsufficientStock error raised when confirming an order #3035
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
When two users try to purchase the last item remaining from a non-backordeable stock location at the same time then the last one will experience an unhandled error
Spree::Order::InsufficientStock
. This happens only if there is a second backorderable stock location for the product.Fix
Improved
Spree::Order.insufficient_stock_lines
method to also map@order.line_items
that are not validated usingSpree::Stock::AvailabilityValidator
.Tests
Added tests from @spaghetticode's gist. Had to improve on it since now validation prevents user to advance to next checkout page.
Closes #3020.
Checklist: