From e290c128bf94a3024fb023f54a77b8a4613bfda7 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Fri, 30 Apr 2021 14:10:43 +0100 Subject: [PATCH] Fix error in Api::ShipmentController#update with :unlock parameter This is a generic issue caused by a clash between state machines trying to define (or failing to define) the #open method on adjustments as part of their state changes interface. This method is already defined in Object. For more details, see: https://github.com/state-machines/state_machines/blob/bb42e33bf736cf3bc3d4ff019be81718fb38e106/lib/state_machines/machine.rb#L323-L350 --- app/controllers/api/v0/shipments_controller.rb | 2 +- spec/controllers/api/v0/shipments_controller_spec.rb | 9 +-------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/app/controllers/api/v0/shipments_controller.rb b/app/controllers/api/v0/shipments_controller.rb index 33706ff971..f2ff7a79d1 100644 --- a/app/controllers/api/v0/shipments_controller.rb +++ b/app/controllers/api/v0/shipments_controller.rb @@ -31,7 +31,7 @@ module Api unlock = params[:shipment].delete(:unlock) if unlock == 'yes' - @shipment.fee_adjustment.open + @shipment.fee_adjustment.fire_events(:open) end if @shipment.update(shipment_params) diff --git a/spec/controllers/api/v0/shipments_controller_spec.rb b/spec/controllers/api/v0/shipments_controller_spec.rb index 99b3840aeb..9720b8df57 100644 --- a/spec/controllers/api/v0/shipments_controller_spec.rb +++ b/spec/controllers/api/v0/shipments_controller_spec.rb @@ -244,7 +244,7 @@ describe Api::V0::ShipmentsController, type: :controller do }.to_not change { order.reload.shipment.fee_adjustment.amount } end - xit "updates closed adjustments with unlock option selected" do + it "updates closed adjustments with unlock option selected" do params[:shipment][:unlock] = "yes" expect { @@ -252,13 +252,6 @@ describe Api::V0::ShipmentsController, type: :controller do expect(response.status).to eq 200 }.to change { order.reload.shipment.fee_adjustment.amount } end - - it "hits a fatal error when the unlock option is used" do - params[:shipment][:unlock] = "yes" - - api_put :update, params - expect(response.status).to eq 422 - end end end end