#4269 - Inclure les pièces jointes des blocs répétables dans le… (#4274)

Instructeur : les pièces jointes des blocs répétables sont maintenant incluses dans l'archive complète du dossier
This commit is contained in:
Pierre de La Morinerie 2019-09-10 16:04:47 +02:00 committed by GitHub
commit 28d869e818
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 3 deletions

View file

@ -1,8 +1,12 @@
class PiecesJustificativesService
def self.liste_pieces_justificatives(dossier)
dossier.champs
.select { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
.filter { |pj| pj.piece_justificative_file.attached? }
champs_blocs_repetables = dossier.champs
.select { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:repetition) }
.flat_map(&:champs)
champs_pieces_justificatives_with_attachments(
champs_blocs_repetables + dossier.champs
)
end
def self.pieces_justificatives_total_size(dossier)
@ -37,4 +41,12 @@ class PiecesJustificativesService
}
end
end
private
def self.champs_pieces_justificatives_with_attachments(champs)
champs
.select { |c| c.type_champ == TypeDeChamp.type_champs.fetch(:piece_justificative) }
.filter { |pj| pj.piece_justificative_file.attached? }
end
end

View file

@ -175,4 +175,18 @@ FactoryBot.define do
create(:champ_number, row: 1, type_de_champ: type_de_champ_number, parent: champ_repetition)
end
end
factory :champ_repetition_with_piece_jointe, class: 'Champs::RepetitionChamp' do
type_de_champ { create(:type_de_champ_repetition) }
after(:build) do |champ_repetition, _evaluator|
type_de_champ_pj0 = create(:type_de_champ_piece_justificative, order_place: 0, parent: champ_repetition.type_de_champ, libelle: 'Justificatif de domicile')
type_de_champ_pj1 = create(:type_de_champ_piece_justificative, order_place: 1, parent: champ_repetition.type_de_champ, libelle: 'Carte d\'identité')
create(:champ_piece_justificative, row: 0, type_de_champ: type_de_champ_pj0, parent: champ_repetition)
create(:champ_piece_justificative, row: 0, type_de_champ: type_de_champ_pj1, parent: champ_repetition)
create(:champ_piece_justificative, row: 1, type_de_champ: type_de_champ_pj0, parent: champ_repetition)
create(:champ_piece_justificative, row: 1, type_de_champ: type_de_champ_pj1, parent: champ_repetition)
end
end
end

View file

@ -15,5 +15,14 @@ describe ActiveStorage::DownloadableFile do
it { expect(list.length).to be 1 }
end
context 'when there is a repetition bloc' do
let(:champ) { build(:champ_repetition_with_piece_jointe) }
let(:dossier) { create(:dossier, :en_construction, champs: [champ]) }
it 'should have 4 piece_justificatives' do
expect(list.size).to eq(4)
end
end
end
end