Merge pull request #8561 from E-L-T/8500-fix-reject-of-dossiers-transfers

fix(dossiers_transfers): users can reject dossiers_transfers
This commit is contained in:
Eric Leroy-Terquem 2023-02-03 14:09:50 +01:00 committed by GitHub
commit d200984f65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 11 deletions

View file

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

View file

@ -1,23 +1,32 @@
describe Users::TransfersController, type: :controller do
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) }
before { sign_in(user) }
let(:sender_user) { create(:user) }
let(:recipient_user) { create(:user) }
let(:dossier) { create(:dossier, user: sender_user) }
describe 'DELETE destroy' do
let(:dossier_transfert) { DossierTransfer.initiate(user.email, [dossier]) }
let(:dossier_transfert) { DossierTransfer.initiate(recipient_user.email, [dossier]) }
subject { delete :destroy, params: { id: dossier_transfert.id } }
before do
delete :destroy, params: { id: dossier_transfert.id }
sign_in(recipient_user)
end
it { expect { dossier_transfert.reload }.to raise_error(ActiveRecord::RecordNotFound) }
it { expect { subject }.not_to raise_error }
it "deletes dossier transfert" do
subject
expect { dossier_transfert.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
describe "POST create" do
subject { post :create, params: { dossier_transfer: { email: email, dossier: dossier.id } } }
before { subject }
before do
sign_in(sender_user)
subject
end
context "with valid email" do
let(:email) { "test@rspec.net" }