From c77b66feef22f2ef11c90f12ae84270e241e324c Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Thu, 11 Apr 2024 11:56:53 +0200 Subject: [PATCH 1/2] refactor: api_geo_services raises if wrong dep or city code --- app/services/api_geo_service.rb | 3 --- spec/services/api_geo_service_spec.rb | 6 ------ 2 files changed, 9 deletions(-) diff --git a/app/services/api_geo_service.rb b/app/services/api_geo_service.rb index d8c0f1c50..18e42f451 100644 --- a/app/services/api_geo_service.rb +++ b/app/services/api_geo_service.rb @@ -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 diff --git a/spec/services/api_geo_service_spec.rb b/spec/services/api_geo_service_spec.rb index 95faa29ba..7dda79ec7 100644 --- a/spec/services/api_geo_service_spec.rb +++ b/spec/services/api_geo_service_spec.rb @@ -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 From 124433b78134070fbb785760f3828ab2155d075a Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 10 Apr 2024 11:08:25 +0200 Subject: [PATCH 2/2] refactor: commune_champ --- app/models/champs/commune_champ.rb | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/app/models/champs/commune_champ.rb b/app/models/champs/commune_champ.rb index d7977c295..8dc7c9903 100644 --- a/app/models/champs/commune_champ.rb +++ b/app/models/champs/commune_champ.rb @@ -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