[Fix #6504] Fix exception raised when deleting a transfer

This commit is contained in:
simon lehericey 2021-10-01 12:10:10 +02:00
parent cc5b3fef42
commit 64351d0287
2 changed files with 20 additions and 1 deletions

View file

@ -12,7 +12,10 @@ module Users
end
def destroy
transfer = DossierTransfer.find_by!(id: params[:id], dossiers: { user: current_user })
transfer = DossierTransfer
.joins(:dossiers)
.find_by!(id: params[:id], dossiers: { user: current_user })
transfer.destroy
redirect_to dossiers_path
end

View file

@ -0,0 +1,16 @@
describe Users::TransfersController, type: :controller do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) }
before { sign_in(user) }
describe 'DELETE destroy' do
let(:dossier_transfert) { DossierTransfer.initiate(user.email, [dossier]) }
before do
delete :destroy, params: { id: dossier_transfert.id }
end
it { expect { dossier_transfert.reload }.to raise_error(ActiveRecord::RecordNotFound) }
end
end