Merge pull request #10301 from demarches-simplifiees/more_work_on_city_address

Tech: simplifie le code address dans les champs commune
This commit is contained in:
Paul Chavard 2024-04-11 10:15:47 +00:00 committed by GitHub
commit 2de2d8af45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 2 additions and 20 deletions

View file

@ -57,20 +57,11 @@ class Champs::CommuneChamp < Champs::TextChamp
alias postal_code code_postal
def name
if departement? && code?
APIGeoService.commune_name(code_departement, code).presence || safe_to_s
else
safe_to_s
end
APIGeoService.safely_normalize_city_name(code_departement, code, safe_to_s)
end
def to_s
if departement? && code_postal? && code?
name = APIGeoService.commune_name(code_departement, code)
name.present? ? "#{name} (#{code_postal})" : safe_to_s
else
safe_to_s
end
code_postal? ? "#{name} (#{code_postal})" : name
end
def code

View file

@ -126,9 +126,6 @@ class APIGeoService
return fallback if department_code.nil? || city_code.nil?
commune_name(department_code, city_code) || fallback
rescue StandardError
fallback
end
private

View file

@ -130,11 +130,5 @@ describe APIGeoService do
it { is_expected.to eq('Paris') }
end
context 'with a wrong department' do
let(:department_code) { 'wrong' }
it { is_expected.to eq('Paris') }
end
end
end