Merge pull request #3431 from betagouv/frederic/fix_nil

Fix undefined method for nil:NilClass
This commit is contained in:
Paul Chavard 2019-02-13 19:29:32 +01:00 committed by GitHub
commit c3189ed34e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View file

@ -49,7 +49,7 @@ class Etablissement < ApplicationRecord
"#{numero_voie} #{type_voie} #{nom_voie}",
complement_adresse,
"#{code_postal} #{localite}"
].map { |s| s.squeeze(' ') }.reject(&:blank?).join(', ')
].reject(&:blank?).join(', ').squeeze(' ')
end
def verify

View file

@ -15,9 +15,26 @@ describe Etablissement do
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: '') }
let(:expected_adresse) { '6 RUE RAOUL NORDLING, 92270 BOIS COLOMBES' }
subject { etablissement.inline_adresse }
it { expect(etablissement.inline_adresse).to eq '6 RUE RAOUL NORDLING, 92270 BOIS COLOMBES' }
context 'when blank' do
let(:etablissement) { create(:etablissement, complement_adresse: '') }
it { is_expected.to eq expected_adresse }
end
context 'when whitespace' do
let(:etablissement) { create(:etablissement, complement_adresse: ' ') }
it { is_expected.to eq expected_adresse }
end
context 'when nil' do
let(:etablissement) { create(:etablissement, complement_adresse: nil) }
it { is_expected.to eq expected_adresse }
end
end
end