mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-29 21:17:17 +00:00
Move required logic into OrderContents and improve spec
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user