From df2eaa95425b39d2047d5af3cd73ec078e3ab821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Carceles?= Date: Wed, 11 Jan 2023 15:04:45 +0100 Subject: [PATCH] don't clean the siret champ value Cleaning the value is useless, when fetching the etablissement, as the value will be re-written by the dossier update, when the user fills in the dossier. --- ...t_champ_etablissement_fetchable_concern.rb | 2 +- .../champs/siret_controller_spec.rb | 24 +++++++------------ ...mp_etablissement_fetchable_concern_spec.rb | 2 -- 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/app/models/concerns/siret_champ_etablissement_fetchable_concern.rb b/app/models/concerns/siret_champ_etablissement_fetchable_concern.rb index 8d53f0a4c..3beb7b652 100644 --- a/app/models/concerns/siret_champ_etablissement_fetchable_concern.rb +++ b/app/models/concerns/siret_champ_etablissement_fetchable_concern.rb @@ -27,7 +27,7 @@ module SiretChampEtablissementFetchableConcern def clear(error: nil) etablissement_to_destroy = etablissement - update!(value: '', etablissement: nil) + update!(etablissement: nil) etablissement_to_destroy&.destroy error.presence end diff --git a/spec/controllers/champs/siret_controller_spec.rb b/spec/controllers/champs/siret_controller_spec.rb index daee4b3da..36dcca443 100644 --- a/spec/controllers/champs/siret_controller_spec.rb +++ b/spec/controllers/champs/siret_controller_spec.rb @@ -39,10 +39,8 @@ describe Champs::SiretController, type: :controller do context 'when the SIRET is empty' do subject! { get :show, params: params, format: :turbo_stream } - it 'clears the etablissement and SIRET on the model' do - champ.reload - expect(champ.etablissement).to be_nil - expect(champ.value).to be_empty + it 'clears the etablissement on the model' do + expect(champ.reload.etablissement).to be_nil end it 'clears any information or error message' do @@ -55,10 +53,8 @@ describe Champs::SiretController, type: :controller do subject! { get :show, params: params, format: :turbo_stream } - it 'clears the etablissement and SIRET on the model' do - champ.reload - expect(champ.etablissement).to be_nil - expect(champ.value).to be_empty + it 'clears the etablissement on the model' do + expect(champ.reload.etablissement).to be_nil end it 'displays a “SIRET is invalid” error message' do @@ -76,10 +72,8 @@ describe Champs::SiretController, type: :controller do subject! { get :show, params: params, format: :turbo_stream } - it 'clears the etablissement and SIRET on the model' do - champ.reload - expect(champ.etablissement).to be_nil - expect(champ.value).to be_empty + it 'clears the etablissement on the model' do + expect(champ.reload.etablissement).to be_nil end it 'displays a “API is unavailable” error message' do @@ -115,10 +109,8 @@ describe Champs::SiretController, type: :controller do subject! { get :show, params: params, format: :turbo_stream } - it 'clears the etablissement and SIRET on the model' do - champ.reload - expect(champ.etablissement).to be_nil - expect(champ.value).to be_empty + it 'clears the etablissement on the model' do + expect(champ.reload.etablissement).to be_nil end it 'displays a “SIRET not found” error message' do diff --git a/spec/models/concern/siret_champ_etablissement_fetchable_concern_spec.rb b/spec/models/concern/siret_champ_etablissement_fetchable_concern_spec.rb index 77b754dac..c916bc7b9 100644 --- a/spec/models/concern/siret_champ_etablissement_fetchable_concern_spec.rb +++ b/spec/models/concern/siret_champ_etablissement_fetchable_concern_spec.rb @@ -16,8 +16,6 @@ RSpec.describe SiretChampEtablissementFetchableConcern do subject(:fetch_etablissement!) { champ.fetch_etablissement!(siret, build_stubbed(:user)) } shared_examples 'an error occured' do |error| - it { expect { fetch_etablissement! }.to change { champ.reload.value }.to('') } - it { expect { fetch_etablissement! }.to change { champ.reload.etablissement }.to(nil) } it { expect { fetch_etablissement! }.to change { Etablissement.count }.by(-1) }