From 41ab7246cf15b79521c8f311d4ecd51b8a4da42c Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Wed, 13 Feb 2019 09:57:33 +0100 Subject: [PATCH] [#3424] Improve formatting of addresses with missing components --- app/models/etablissement.rb | 6 +++++- spec/models/etablissement_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/models/etablissement.rb b/app/models/etablissement.rb index 44e5142e9..2c10e54b5 100644 --- a/app/models/etablissement.rb +++ b/app/models/etablissement.rb @@ -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 diff --git a/spec/models/etablissement_spec.rb b/spec/models/etablissement_spec.rb index 31988c14d..46e110411 100644 --- a/spec/models/etablissement_spec.rb +++ b/spec/models/etablissement_spec.rb @@ -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