Merge pull request #10814 from demarches-simplifiees/fix-10813

[bug] Ne pas afficher de 500 quand value_json d'un champ SIRET est nil
This commit is contained in:
mfo 2024-09-19 15:22:45 +00:00 committed by GitHub
commit cd8c55b161
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View file

@ -20,7 +20,7 @@ class AddressProxy
end
def initialize(champ)
@data = champ.value_json.with_indifferent_access
@data = champ.value_json&.with_indifferent_access || {}
end
end

View file

@ -0,0 +1,26 @@
# frozen_string_literal: true
RSpec.describe AddressProxy, type: :model do
describe '#initialize' do
subject { AddressProxy.new(champ_or_etablissement) }
context 'when champ_or_etablissement is an instance of Champ' do
let(:champ_or_etablissement) { Champ.new }
context 'when value_json is nil' do
before { allow(champ_or_etablissement).to receive(:value_json).and_return(nil) }
it do
expect(subject.street_address).to be_nil
expect(subject.city_name).to be_nil
expect(subject.postal_code).to be_nil
expect(subject.city_code).to be_nil
expect(subject.departement_name).to be_nil
expect(subject.departement_code).to be_nil
expect(subject.region_name).to be_nil
expect(subject.region_code).to be_nil
end
end
end
end
end