fix(user dossiers index): do not crash with a deleted dossier and a discarded procedure

This commit is contained in:
simon lehericey 2023-06-08 17:28:08 +02:00 committed by LeSim
parent e2d7be215e
commit 44859b8217
3 changed files with 14 additions and 4 deletions

View file

@ -27,7 +27,7 @@ module Users
@dossiers_traites = current_user.dossiers.state_termine.merge(dossiers_visibles)
@dossiers_invites = current_user.dossiers_invites.merge(dossiers_visibles)
@dossiers_supprimes_recemment = current_user.dossiers.hidden_by_user.merge(dossiers)
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.order_by_updated_at
@dossiers_supprimes_definitivement = current_user.deleted_dossiers.includes(:procedure).order_by_updated_at
@dossier_transfers = DossierTransfer.for_email(current_user.email)
@dossiers_close_to_expiration = current_user.dossiers.close_to_expiration.merge(dossiers_visibles)
@statut = statut(@user_dossiers, @dossiers_traites, @dossiers_invites, @dossiers_supprimes_recemment, @dossiers_supprimes_definitivement, @dossier_transfers, @dossiers_close_to_expiration, params[:statut])

View file

@ -13,14 +13,12 @@
%th Date de suppression
%tbody
- deleted_dossiers.each do |dossier|
- libelle_demarche = Procedure.find(dossier.procedure_id).libelle
%tr{ data: { 'dossier-id': dossier.dossier_id } }
%td.number-col
%span.icon.folder
= dossier.dossier_id
%td
= libelle_demarche
= dossier.procedure.libelle
%td.cell-link
= deletion_reason_badge(dossier.reason)

View file

@ -913,6 +913,18 @@ describe Users::DossiersController, type: :controller do
expect(assigns(:dossiers_invites).second.updated_at.to_date).to eq(4.days.ago.to_date)
end
end
context 'when the user has a deleted dossier on a discarded procedure' do
render_views
let!(:deleted_dossier) { create(:deleted_dossier, user_id: user.id) }
before { deleted_dossier.procedure.discard! }
subject { get(:index, params: { statut: 'dossiers-supprimes-definitivement' }) }
it { is_expected.to have_http_status(200) }
end
end
describe '#show' do