diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 2fe7dd2e6..49ffade30 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -454,7 +454,10 @@ class Procedure < ApplicationRecord } include_list[:groupe_instructeurs] = :instructeurs if !is_different_admin procedure = self.deep_clone(include: include_list) do |original, kopy| - PiecesJustificativesService.clone_attachments(original, kopy) + begin + PiecesJustificativesService.clone_attachments(original, kopy) + rescue ActiveStorage::FileNotFoundError + end end procedure.path = SecureRandom.uuid procedure.aasm_state = :brouillon diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index b5327b1ff..d2a3f4ecf 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -647,6 +647,16 @@ describe Procedure do expect(subject.canonical_procedure).to be_nil end end + + context 'with an pj not found' do + let(:procedure) { create(:procedure) } + + before do + expect(PiecesJustificativesService).to receive(:clone_attachments).at_least(:once).and_raise(ActiveStorage::FileNotFoundError) + end + + it { expect { procedure.clone(administrateur, false) }.not_to raise_error } + end end describe '#publish!' do