Fix repetition data export

This commit is contained in:
Paul Chavard 2019-07-30 15:10:01 +02:00
parent d1ff311879
commit 5a9468aa95
2 changed files with 15 additions and 8 deletions

View file

@ -53,15 +53,17 @@ class ProcedureExportV2Service
[dossier.champs, dossier.champs_private] [dossier.champs, dossier.champs_private]
.flatten .flatten
.select { |champ| champ.is_a?(Champs::RepetitionChamp) } .select { |champ| champ.is_a?(Champs::RepetitionChamp) }
end end.group_by(&:libelle)
end end
def champs_repetables_options def champs_repetables_options
champs_repetables.map do |champ| champs_repetables.map do |libelle, champs|
[ [
champ.libelle, libelle,
champ.rows.each_with_index.map do |champs, index| champs.flat_map do |champ|
Champs::RepetitionChamp::Row.new(index: index + 1, dossier_id: champ.dossier_id.to_s, champs: champs) champ.rows.each_with_index.map do |champs, index|
Champs::RepetitionChamp::Row.new(index: index + 1, dossier_id: champ.dossier_id.to_s, champs: champs)
end
end end
] ]
end end

View file

@ -155,8 +155,13 @@ describe ProcedureExportV2Service do
end end
context 'with repetitions' do context 'with repetitions' do
let!(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure) } let!(:dossiers) do
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } } [
create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure),
create(:dossier, :en_instruction, :with_all_champs, :for_individual, procedure: procedure)
]
end
let(:champ_repetition) { dossiers.first.champs.find { |champ| champ.type_champ == 'repetition' } }
it 'should have sheets' do it 'should have sheets' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle]) expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis', champ_repetition.libelle])
@ -172,7 +177,7 @@ describe ProcedureExportV2Service do
end end
it 'should have data' do it 'should have data' do
expect(repetition_sheet.data.size).to eq(2) expect(repetition_sheet.data.size).to eq(4)
end end
end end
end end