Move required logic into OrderContents and improve spec

This commit is contained in:
Matt-Yorkley
2021-05-12 11:40:56 +01:00
parent 42ff2307fa
commit 0cfe7fdc45
3 changed files with 4 additions and 5 deletions

View File

@@ -33,9 +33,6 @@ module Admin
# and https://www.postgresql.org/docs/current/static/sql-select.html#SQL-FOR-UPDATE-SHARE
order.with_lock do
if order.contents.update_item(@line_item, line_item_params)
order.update_line_item_fees! @line_item
order.update_order_fees!
order.update_order!
render body: nil, status: :no_content # No Content, does not trigger ng resource auto-update
else
render json: { errors: @line_item.errors }, status: :precondition_failed

View File

@@ -56,6 +56,8 @@ module Spree
def update_item(line_item, params)
if line_item.update_attributes(params)
order.update_line_item_fees! line_item
order.update_order_fees! if order.completed?
discard_empty_line_items
order.ensure_updated_shipments
update_order

View File

@@ -209,10 +209,10 @@ describe Admin::BulkLineItemsController, type: :controller do
allow(Spree::LineItem)
.to receive(:find).with(line_item1.id.to_s).and_return(line_item1)
expect(line_item1.order).to receive(:reload).with(lock: true)
expect(line_item1.order).to receive(:with_lock).and_call_original
expect(line_item1.order).to receive(:update_line_item_fees!)
expect(line_item1.order).to receive(:update_order_fees!)
expect(line_item1.order).to receive(:update_order!)
expect(line_item1.order).to receive(:update_order!).once
spree_put :update, params
end