[#3424] Improve formatting of addresses with missing components

This commit is contained in:
Frederic Merizen 2019-02-13 09:57:33 +01:00
parent 8750d0e410
commit 41ab7246cf
2 changed files with 11 additions and 1 deletions

View file

@ -45,7 +45,11 @@ class Etablissement < ApplicationRecord
def inline_adresse
# squeeze needed because of space in excess in the data
"#{numero_voie} #{type_voie} #{nom_voie}, #{complement_adresse}, #{code_postal} #{localite}".squeeze(' ')
[
"#{numero_voie} #{type_voie} #{nom_voie}",
complement_adresse,
"#{code_postal} #{localite}"
].map { |s| s.squeeze(' ') }.reject(&:blank?).join(', ')
end
def verify

View file

@ -13,6 +13,12 @@ describe Etablissement do
let(:etablissement) { create(:etablissement, nom_voie: 'green moon') }
it { expect(etablissement.inline_adresse).to eq '6 RUE green moon, IMMEUBLE BORA, 92270 BOIS COLOMBES' }
context 'with missing complement adresse' do
let(:etablissement) { create(:etablissement, complement_adresse: '') }
it { expect(etablissement.inline_adresse).to eq '6 RUE RAOUL NORDLING, 92270 BOIS COLOMBES' }
end
end
describe '#verify' do