diff --git a/app/services/pieces_justificatives_service.rb b/app/services/pieces_justificatives_service.rb index 1d337f52c..08b358d4c 100644 --- a/app/services/pieces_justificatives_service.rb +++ b/app/services/pieces_justificatives_service.rb @@ -56,7 +56,9 @@ class PiecesJustificativesService include_infos_administration: true, dossier: dossier }) - dossier.pdf_export_for_instructeur.attach(io: StringIO.open(pdf), filename: "export-#{dossier.id}.pdf", content_type: 'application/pdf') + ActiveRecord::Base.no_touching do + dossier.pdf_export_for_instructeur.attach(io: StringIO.open(pdf), filename: "export-#{dossier.id}.pdf", content_type: 'application/pdf') + end dossier.pdf_export_for_instructeur end diff --git a/spec/services/pieces_justificatives_service_spec.rb b/spec/services/pieces_justificatives_service_spec.rb index b4e7b01a9..652ea9819 100644 --- a/spec/services/pieces_justificatives_service_spec.rb +++ b/spec/services/pieces_justificatives_service_spec.rb @@ -44,4 +44,18 @@ describe PiecesJustificativesService do expect(subject.any? { |piece| piece.name == 'serialized' }).to be_truthy end end + + describe '.generate_dossier_export' do + subject { PiecesJustificativesService.generate_dossier_export(dossier) } + it "generates pdf export for instructeur" do + subject + expect(dossier.pdf_export_for_instructeur).to be_attached + end + + it "doesn't update dossier" do + before_export = Time.zone.now + subject + expect(dossier.updated_at).to be <= before_export + end + end end