Merge pull request #3425 from betagouv/frederic/fix_3424-formattage_adresses

[#3424] Improve formatting of addresses with missing components
This commit is contained in:
Paul Chavard 2019-02-13 11:55:18 +01:00 committed by GitHub
commit 55d72554ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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