fix dossier directory for etablissement when export with export template
This commit is contained in:
parent
2267ec98cf
commit
d9f7b6d1df
3 changed files with 18 additions and 2 deletions
|
@ -128,7 +128,7 @@ class ExportTemplate < ApplicationRecord
|
|||
'messagerie'
|
||||
when 'Avis'
|
||||
'avis'
|
||||
when 'Attestation'
|
||||
when 'Attestation', 'Etablissement'
|
||||
'pieces_justificatives'
|
||||
else
|
||||
# for attachment
|
||||
|
|
|
@ -195,9 +195,14 @@ class PiecesJustificativesService
|
|||
.where(record_type: "Etablissement", record_id: etablissement_id_dossier_id.keys)
|
||||
.map do |a|
|
||||
dossier_id = etablissement_id_dossier_id[a.record_id]
|
||||
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
|
||||
|
||||
def motivations(dossiers)
|
||||
ActiveStorage::Attachment
|
||||
|
|
|
@ -236,6 +236,17 @@ describe PiecesJustificativesService do
|
|||
end
|
||||
|
||||
it { expect(subject).to match_array([attestation_sociale.attachment, attestation_fiscale.attachment]) }
|
||||
|
||||
it 'uses default name for dossier directory' do
|
||||
expect(PiecesJustificativesService.new(user_profile:, export_template: nil).liste_documents(dossiers).map(&:second)[0].starts_with?("dossier-#{dossier.id}/pieces_justificatives")).to be true
|
||||
end
|
||||
|
||||
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}/pieces_justificatives")).to be true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue