From fdec9b2fd5c380f1c5353cbf43262fb2289c8c64 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Fri, 18 Jun 2021 09:06:05 +0200 Subject: [PATCH] archives: don't update dossiers this fix avoid to touch dossier after attaching pdf_export_for_instructeur --- app/services/pieces_justificatives_service.rb | 4 +++- .../services/pieces_justificatives_service_spec.rb | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) 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