fix(attachment): clone piece justificatives with multiple attachments

This commit is contained in:
Colin Darie 2022-11-22 10:04:56 +01:00
parent b609c3dae4
commit 7cbe6bbaa4
2 changed files with 4 additions and 2 deletions

View file

@ -60,7 +60,9 @@ class PiecesJustificativesService
def self.clone_attachments(original, kopy)
case original
when Champs::PieceJustificativeChamp, Champs::TitreIdentiteChamp
clone_attachment(original.piece_justificative_file, kopy.piece_justificative_file)
original.piece_justificative_file.attachments.each do |attachment|
kopy.piece_justificative_file.attach(attachment.blob)
end
when TypeDeChamp
clone_attachment(original.piece_justificative_template, kopy.piece_justificative_template)
when Procedure

View file

@ -1783,7 +1783,7 @@ describe Dossier do
let(:dossier) { create(:dossier) }
let(:champ_piece_justificative) { create(:champ_piece_justificative, dossier_id: dossier.id) }
before { dossier.champs_public << champ_piece_justificative }
it { expect(Champs::PieceJustificativeChamp.where(dossier: new_dossier).first.piece_justificative_file.blob).to eq(champ_piece_justificative.piece_justificative_file.blob) }
it { expect(Champs::PieceJustificativeChamp.where(dossier: new_dossier).first.piece_justificative_file.first.blob).to eq(champ_piece_justificative.piece_justificative_file.first.blob) }
end
end