diff --git a/app/models/champs/address_champ.rb b/app/models/champs/address_champ.rb index 4031cf11751..d929a73bbbc 100644 --- a/app/models/champs/address_champ.rb +++ b/app/models/champs/address_champ.rb @@ -61,7 +61,7 @@ def departement def commune_name if full_address? - "#{APIGeoService.commune_name(department_code, address['city_code'])} (#{address['postal_code']})" + "#{APIGeoService.commune_name(address.fetch('department_code'), address['city_code'])} (#{address['postal_code']})" end end diff --git a/spec/models/champs/address_champ_spec.rb b/spec/models/champs/address_champ_spec.rb index d9220569eb6..ed86d7d6f4d 100644 --- a/spec/models/champs/address_champ_spec.rb +++ b/spec/models/champs/address_champ_spec.rb @@ -32,6 +32,7 @@ it { expect(champ.address_label).to eq('33 Rue Rébeval 75019 Paris') } it { expect(champ.full_address?).to be_truthy } it { expect(champ.commune).to eq({ name: 'Paris 19e Arrondissement', code: '75119', postal_code: '75019' }) } + it { expect(champ.commune_name).to eq('Paris 19e Arrondissement (75019)') } end context "with wrong code INSEE" do