diff --git a/app/models/champs/commune_champ.rb b/app/models/champs/commune_champ.rb index 526814c52..ce2a67cc5 100644 --- a/app/models/champs/commune_champ.rb +++ b/app/models/champs/commune_champ.rb @@ -23,7 +23,7 @@ class Champs::CommuneChamp < Champs::TextChamp store_accessor :value_json, :departement, :code_departement def for_export - [value, external_id] + [value, external_id, departement? ? departement_code_and_name : ''] end def name_departement diff --git a/app/models/types_de_champ/commune_type_de_champ.rb b/app/models/types_de_champ/commune_type_de_champ.rb index 80994bf53..6ead9e2b7 100644 --- a/app/models/types_de_champ/commune_type_de_champ.rb +++ b/app/models/types_de_champ/commune_type_de_champ.rb @@ -1,5 +1,5 @@ class TypesDeChamp::CommuneTypeDeChamp < TypesDeChamp::TypeDeChampBase def libelle_for_export(index) - [libelle, "#{libelle} (Code insee)"][index] + [libelle, "#{libelle} (Code insee)", "#{libelle} (Département)"][index] end end diff --git a/spec/models/champs/commune_champ_spec.rb b/spec/models/champs/commune_champ_spec.rb index fda2cb373..d39cbb9b6 100644 --- a/spec/models/champs/commune_champ_spec.rb +++ b/spec/models/champs/commune_champ_spec.rb @@ -1,10 +1,19 @@ describe Champs::CommuneChamp do let(:type_de_champ) { create(:type_de_champ_communes, libelle: 'Ma commune') } - let(:champ) { Champs::CommuneChamp.new(value: value, external_id: code_insee, type_de_champ: type_de_champ) } + let(:champ) { Champs::CommuneChamp.new(value: value, external_id: code_insee, departement: departement, code_departement: code_departement, type_de_champ: type_de_champ) } let(:value) { 'Châteldon (63290)' } let(:code_insee) { '63102' } + let(:departement) { '' } + let(:code_departement) { '' } it { expect(champ.value).to eq('Châteldon (63290)') } it { expect(champ.external_id).to eq('63102') } - it { expect(champ.for_export).to eq(['Châteldon (63290)', '63102']) } + it { expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '']) } + + context do + let(:departement) { 'Puy-de-Dôme' } + let(:code_departement) { '63' } + + it { expect(champ.for_export).to eq(['Châteldon (63290)', '63102', '63 - Puy-de-Dôme']) } + end end diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index 01e6d2368..18108847f 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1464,7 +1464,7 @@ describe Dossier do it "should have champs from all revisions" do expect(dossier.types_de_champ.map(&:libelle)).to eq([text_type_de_champ.libelle, datetime_type_de_champ.libelle, "Yes/no", explication_type_de_champ.libelle, commune_type_de_champ.libelle, repetition_type_de_champ.libelle]) expect(dossier_second_revision.types_de_champ.map(&:libelle)).to eq([datetime_type_de_champ.libelle, "Updated yes/no", explication_type_de_champ.libelle, 'Commune de naissance', "Repetition", "New text field"]) - expect(dossier_champs_for_export.map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, text_type_de_champ.libelle, "Updated yes/no", "Commune de naissance", "Commune de naissance (Code insee)", "New text field"]) + expect(dossier_champs_for_export.map { |(libelle)| libelle }).to eq([datetime_type_de_champ.libelle, text_type_de_champ.libelle, "Updated yes/no", "Commune de naissance", "Commune de naissance (Code insee)", "Commune de naissance (Département)", "New text field"]) expect(dossier_champs_for_export).to eq(dossier_second_revision_champs_for_export) 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) @@ -1483,7 +1483,7 @@ describe Dossier do repetition = proc_test.types_de_champ_for_procedure_presentation.repetition.first type_champs = proc_test.types_de_champ_for_procedure_presentation(repetition).to_a expect(type_champs.size).to eq(1) - expect(Dossier.champs_for_export(dossier.champs, type_champs).size).to eq(2) + expect(Dossier.champs_for_export(dossier.champs, type_champs).size).to eq(3) end end end diff --git a/spec/services/procedure_export_service_spec.rb b/spec/services/procedure_export_service_spec.rb index 5dfaaceb3..cda5a864f 100644 --- a/spec/services/procedure_export_service_spec.rb +++ b/spec/services/procedure_export_service_spec.rb @@ -69,6 +69,7 @@ describe ProcedureExportService do "departements", "communes", "communes (Code insee)", + "communes (Département)", "engagement", "dossier_link", "piece_justificative", @@ -160,6 +161,7 @@ describe ProcedureExportService do "departements", "communes", "communes (Code insee)", + "communes (Département)", "engagement", "dossier_link", "piece_justificative", @@ -245,6 +247,7 @@ describe ProcedureExportService do "departements", "communes", "communes (Code insee)", + "communes (Département)", "engagement", "dossier_link", "piece_justificative",