diff --git a/app/lib/active_storage/downloadable_file.rb b/app/lib/active_storage/downloadable_file.rb index d8ca5cf4c..25813202b 100644 --- a/app/lib/active_storage/downloadable_file.rb +++ b/app/lib/active_storage/downloadable_file.rb @@ -1,6 +1,7 @@ class ActiveStorage::DownloadableFile def self.create_list_from_dossier(dossier) - pjs = PiecesJustificativesService.liste_pieces_justificatives(dossier) + dossier_export = PiecesJustificativesService.generate_dossier_export(dossier) + pjs = [dossier_export] + PiecesJustificativesService.liste_pieces_justificatives(dossier) pjs.map do |piece_justificative| [ piece_justificative, diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index f3cd8303c..3c20ab32d 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -1,11 +1,10 @@ class PiecesJustificativesService def self.liste_pieces_justificatives(dossier) - dossier_export = generate_dossier_export(dossier) pjs_champs = pjs_for_champs(dossier) pjs_commentaires = pjs_for_commentaires(dossier) pjs_dossier = pjs_for_dossier(dossier) - ([dossier_export] + pjs_champs + pjs_commentaires + pjs_dossier) + (pjs_champs + pjs_commentaires + pjs_dossier) .filter(&:attached?) end @@ -42,8 +41,6 @@ class PiecesJustificativesService end end - private - def self.generate_dossier_export(dossier) pdf = ApplicationController .render(template: 'dossiers/show', formats: [:pdf], @@ -55,6 +52,8 @@ class PiecesJustificativesService dossier.pdf_export_for_instructeur end + private + def self.pjs_for_champs(dossier) allowed_champs = dossier.champs + dossier.champs_private diff --git a/spec/services/pieces_justificatives_service_spec.rb b/spec/services/pieces_justificatives_service_spec.rb index fc151f908..13d843563 100644 --- a/spec/services/pieces_justificatives_service_spec.rb +++ b/spec/services/pieces_justificatives_service_spec.rb @@ -19,9 +19,8 @@ describe PiecesJustificativesService do expect(subject.any? { |piece| piece.name == 'piece_justificative_file' }).to be_falsy end - it 'returns export pdf of the dossier' do - expect(champ_identite.piece_justificative_file).to be_attached - expect(subject.any? { |piece| piece.name == 'pdf_export_for_instructeur' }).to be_truthy + it "doesn't return export pdf of the dossier" do + expect(subject.any? { |piece| piece.name == 'pdf_export_for_instructeur' }).to be_falsy end end end