diff --git a/app/models/procedure.rb b/app/models/procedure.rb index ec972a7c0..276a90183 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -205,6 +205,10 @@ class Procedure < ApplicationRecord [:notice, :deliberation].each { |attachment| clone_attachment(procedure, attachment) } procedure.types_de_champ += PiecesJustificativesService.types_pj_as_types_de_champ(self) + if is_different_admin || from_library + procedure.types_de_champ.each { |tdc| tdc.options&.delete(:old_pj) } + end + procedure.administrateur = admin procedure.initiated_mail = initiated_mail&.dup procedure.received_mail = received_mail&.dup diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 4cafa657a..f69fffc46 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -409,6 +409,12 @@ describe Procedure do it 'should set service_id to nil' do expect(subject.service).to eq(nil) end + + it 'should discard old pj information' do + subject.types_de_champ.each do |stc| + expect(stc.old_pj).to be_nil + end + end end it 'should keep service_id' do @@ -423,6 +429,12 @@ describe Procedure do expect(subject.service.administrateur_id).not_to eq(service.administrateur_id) expect(subject.service.attributes.except("id", "administrateur_id", "created_at", "updated_at")).to eq(service.attributes.except("id", "administrateur_id", "created_at", "updated_at")) end + + it 'should discard old pj information' do + subject.types_de_champ.each do |stc| + expect(stc.old_pj).to be_nil + end + end end it 'should duplicate existing mail_templates' do