fix dossier directory for motivation when export with export template

This commit is contained in:
Christophe Robillard 2024-05-28 11:28:13 +02:00
parent 08c079ca0b
commit 4232cc98c7
2 changed files with 13 additions and 1 deletions

View file

@ -206,7 +206,12 @@ class PiecesJustificativesService
.filter { |a| safe_attachment(a) }
.map do |a|
dossier_id = a.record_id
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
if @export_template
dossier = dossiers.find { _1.id == dossier_id }
@export_template.attachment_and_path(dossier, a)
else
ActiveStorage::DownloadableFile.pj_and_path(dossier_id, a)
end
end
end

View file

@ -187,6 +187,13 @@ describe PiecesJustificativesService do
let!(:witness) { create(:dossier, :with_justificatif) }
it { expect(subject).to match_array(dossier.justificatif_motivation.attachment) }
context 'with export_template' do
let(:export_template) { create(:export_template, :with_custom_ddd_prefix, ddd_prefix: "DOSSIER-", groupe_instructeur: procedure.defaut_groupe_instructeur) }
it 'uses specific name for dossier directory' do
expect(PiecesJustificativesService.new(user_profile:, export_template:).liste_documents(dossiers).map(&:second)[0].starts_with?("DOSSIER-#{dossier.id}/dossier")).to be true
end
end
end
context 'with a motivation not safe' do