fix(champ): may fix pg deadlocks: autosave already saves value at the same time
This commit is contained in:
parent
76cf93c189
commit
954652fcf5
3 changed files with 1 additions and 8 deletions
|
@ -9,12 +9,11 @@ module SiretChampEtablissementFetchableConcern
|
||||||
return clear_etablissement!(:invalid_checksum) if invalid_because?(siret, :checksum) # i18n-tasks-use t('errors.messages.invalid_siret_checksum')
|
return clear_etablissement!(:invalid_checksum) if invalid_because?(siret, :checksum) # i18n-tasks-use t('errors.messages.invalid_siret_checksum')
|
||||||
return clear_etablissement!(:not_found) unless (etablissement = APIEntrepriseService.create_etablissement(self, siret, user&.id)) # i18n-tasks-use t('errors.messages.siret_not_found')
|
return clear_etablissement!(:not_found) unless (etablissement = APIEntrepriseService.create_etablissement(self, siret, user&.id)) # i18n-tasks-use t('errors.messages.siret_not_found')
|
||||||
|
|
||||||
update!(value: siret, etablissement: etablissement)
|
update!(etablissement: etablissement)
|
||||||
rescue => error
|
rescue => error
|
||||||
if error.try(:network_error?) && !APIEntrepriseService.api_up?
|
if error.try(:network_error?) && !APIEntrepriseService.api_up?
|
||||||
# TODO: notify ops
|
# TODO: notify ops
|
||||||
update!(
|
update!(
|
||||||
value: siret,
|
|
||||||
etablissement: APIEntrepriseService.create_etablissement_as_degraded_mode(self, siret, user.id)
|
etablissement: APIEntrepriseService.create_etablissement_as_degraded_mode(self, siret, user.id)
|
||||||
)
|
)
|
||||||
@etablissement_fetch_error_key = :api_entreprise_down
|
@etablissement_fetch_error_key = :api_entreprise_down
|
||||||
|
|
|
@ -109,7 +109,6 @@ describe Champs::SiretController, type: :controller do
|
||||||
|
|
||||||
it 'saves the etablissement in degraded mode and SIRET on the model' do
|
it 'saves the etablissement in degraded mode and SIRET on the model' do
|
||||||
champ.reload
|
champ.reload
|
||||||
expect(champ.value).to eq(siret)
|
|
||||||
expect(champ.etablissement.siret).to eq(siret)
|
expect(champ.etablissement.siret).to eq(siret)
|
||||||
expect(champ.etablissement.as_degraded_mode?).to be true
|
expect(champ.etablissement.as_degraded_mode?).to be true
|
||||||
end
|
end
|
||||||
|
@ -143,7 +142,6 @@ describe Champs::SiretController, type: :controller do
|
||||||
|
|
||||||
it 'populates the etablissement and SIRET on the model' do
|
it 'populates the etablissement and SIRET on the model' do
|
||||||
champ.reload
|
champ.reload
|
||||||
expect(champ.value).to eq(siret)
|
|
||||||
expect(champ.etablissement.siret).to eq(siret)
|
expect(champ.etablissement.siret).to eq(siret)
|
||||||
expect(champ.etablissement.naf).to eq("6202A")
|
expect(champ.etablissement.naf).to eq("6202A")
|
||||||
expect(dossier.reload.etablissement).to eq(nil)
|
expect(dossier.reload.etablissement).to eq(nil)
|
||||||
|
|
|
@ -68,8 +68,6 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
|
||||||
|
|
||||||
before { expect(APIEntrepriseService).to receive(:api_up?).and_return(false) }
|
before { expect(APIEntrepriseService).to receive(:api_up?).and_return(false) }
|
||||||
|
|
||||||
it { expect { fetch_etablissement! }.to change { champ.reload.value }.to(siret) }
|
|
||||||
|
|
||||||
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement } }
|
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement } }
|
||||||
|
|
||||||
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.as_degraded_mode? }.to(true) }
|
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.as_degraded_mode? }.to(true) }
|
||||||
|
@ -96,8 +94,6 @@ RSpec.describe SiretChampEtablissementFetchableConcern do
|
||||||
let(:api_etablissement_status) { 200 }
|
let(:api_etablissement_status) { 200 }
|
||||||
let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
let(:api_etablissement_body) { File.read('spec/fixtures/files/api_entreprise/etablissements.json') }
|
||||||
|
|
||||||
it { expect { fetch_etablissement! }.to change { champ.reload.value }.to(siret) }
|
|
||||||
|
|
||||||
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.siret }.to(siret) }
|
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.siret }.to(siret) }
|
||||||
|
|
||||||
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.naf }.to("6202A") }
|
it { expect { fetch_etablissement! }.to change { champ.reload.etablissement.naf }.to("6202A") }
|
||||||
|
|
Loading…
Reference in a new issue