This commit is contained in:
simon lehericey 2022-04-07 15:23:18 +02:00
parent ebac71796c
commit 4d3412daf5
3 changed files with 25 additions and 18 deletions

View file

@ -1,8 +1,7 @@
class ActiveStorage::DownloadableFile
def self.create_list_from_dossiers(dossiers, for_expert = false)
dossiers
.map { |d| pj_and_path(d.id, PiecesJustificativesService.generate_dossier_export(d)) } +
PiecesJustificativesService.liste_documents(dossiers, for_expert)
PiecesJustificativesService.generate_dossier_export(dossiers) +
PiecesJustificativesService.liste_documents(dossiers, for_expert)
end
private

View file

@ -107,21 +107,29 @@ class PiecesJustificativesService
end
end
def self.generate_dossier_export(dossier)
pdf = ApplicationController
.render(template: 'dossiers/show', formats: [:pdf],
assigns: {
include_infos_administration: true,
dossier: dossier
})
def self.generate_dossier_export(dossiers)
pdfs = []
FakeAttachment.new(
file: StringIO.new(pdf),
filename: "export-#{dossier.id}.pdf",
name: 'pdf_export_for_instructeur',
id: dossier.id,
created_at: dossier.updated_at
)
dossiers.find_each do |dossier|
pdf = ApplicationController
.render(template: 'dossiers/show', formats: [:pdf],
assigns: {
include_infos_administration: true,
dossier: dossier
})
a = FakeAttachment.new(
file: StringIO.new(pdf),
filename: "export-#{dossier.id}.pdf",
name: 'pdf_export_for_instructeur',
id: dossier.id,
created_at: dossier.updated_at
)
pdfs << ActiveStorage::DownloadableFile.pj_and_path(dossier.id, a)
end
pdfs
end
private

View file

@ -160,7 +160,7 @@ describe PiecesJustificativesService do
describe '.generate_dossier_export' do
let(:dossier) { create(:dossier) }
subject { PiecesJustificativesService.generate_dossier_export(dossier) }
subject { PiecesJustificativesService.generate_dossier_export(Dossier.where(id: dossier.id)) }
it "doesn't update dossier" do
expect { subject }.not_to change { dossier.updated_at }