From cd34e160bf6588b8d554547caa4c7b4bd49efe0e Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 3 Oct 2023 14:52:08 +1100 Subject: [PATCH] Fix deleting of return_authorizations return_authorizations have a stock_location_id, not the other way round. So there's no dependent field to nullify. --- app/models/spree/return_authorization.rb | 2 +- .../admin/return_authorizations_controller_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/models/spree/return_authorization.rb b/app/models/spree/return_authorization.rb index 69858ccf48..ad291f2bf3 100644 --- a/app/models/spree/return_authorization.rb +++ b/app/models/spree/return_authorization.rb @@ -9,7 +9,7 @@ module Spree belongs_to :order, class_name: 'Spree::Order', inverse_of: :return_authorizations has_many :inventory_units, inverse_of: :return_authorization, dependent: :nullify - has_one :stock_location, dependent: :nullify + has_one :stock_location, dependent: nil before_save :force_positive_amount before_create :generate_number diff --git a/spec/controllers/spree/admin/return_authorizations_controller_spec.rb b/spec/controllers/spree/admin/return_authorizations_controller_spec.rb index aaf7bc81d6..d8b0a1ca42 100644 --- a/spec/controllers/spree/admin/return_authorizations_controller_spec.rb +++ b/spec/controllers/spree/admin/return_authorizations_controller_spec.rb @@ -33,6 +33,18 @@ module Spree expect(return_authorization.amount.to_s).to eq "10.2" expect(return_authorization.reason.to_s).to eq "half broken" end + + context "with a return authorization" do + let!(:return_authorization) { create(:return_authorization, order:) } + + it "deletes a return authorization" do + expect{ + spree_delete :destroy, id: return_authorization.id, order_id: order.number + }.to change { order.return_authorizations.without_deleted.count }.by(-1) + + expect(response).to redirect_to spree.admin_order_return_authorizations_url(order.number) + end + end end end end