diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index a2370f2ef..dd132520d 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -190,6 +190,12 @@ FactoryBot.define do end end + trait :with_repetition_commune do + after(:build) do |procedure, _evaluator| + build(:type_de_champ_repetition, types_de_champ: [build(:type_de_champ_communes)], procedure: procedure) + end + end + trait :with_number do after(:build) do |procedure, _evaluator| build(:type_de_champ_number, procedure: procedure) diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index f8ec28d1f..c25a9b6ba 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1458,6 +1458,17 @@ describe Dossier do expect(repetition_second_revision_champs_for_export.map { |(libelle)| libelle }).to eq(procedure.types_de_champ_for_procedure_presentation.repetition.map(&:libelle_for_export)) expect(repetition_second_revision_champs_for_export.first.size).to eq(2) end + + context 'within a repition having a type de champs commune (multiple values for export)' do + it 'works' do + proc_test = create(:procedure, :with_repetition_commune) + dossier_test = create(:dossier, procedure: proc_test) + repetition = proc_test.types_de_champ_for_procedure_presentation.repetition.first + type_champs = repetition.types_de_champ_for_revision(proc_test.active_revision).to_a + expect(type_champs.size).to eq(1) + expect(Dossier.champs_for_export(dossier.champs, type_champs).size).to eq(2) + end + end end context "when procedure brouillon" do