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