test(brouillon_spec): fix random errors due to db champs not yet updated
This commit is contained in:
parent
e8b088c2c5
commit
9ebcbbbd67
1 changed files with 42 additions and 26 deletions
|
@ -47,8 +47,15 @@ describe 'The user' do
|
|||
blur
|
||||
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
|
||||
|
||||
# check data on the dossier
|
||||
expect(user_dossier.brouillon?).to be true
|
||||
# check data on the dossier from db
|
||||
# Sometimes, `user_dossier.champs` are not yet all updated with the new values
|
||||
# when we first load `user_dossier`, causing random errors.
|
||||
# Strategy is to retry & reload them if necessary for a few seconds,
|
||||
# and raise expectation error instead of timeout error.
|
||||
last_expection_error = nil
|
||||
begin
|
||||
Timeout.timeout(Capybara.default_max_wait_time) do
|
||||
expect(user_dossier).to be_brouillon
|
||||
expect(champ_value_for('text')).to eq('super texte')
|
||||
expect(champ_value_for('textarea')).to eq('super textarea')
|
||||
expect(champ_value_for('date')).to eq('2012-12-12')
|
||||
|
@ -70,8 +77,17 @@ describe 'The user' do
|
|||
expect(champ_value_for('departements')).to eq('02 - Aisne')
|
||||
expect(champ_value_for('communes')).to eq('Ambléon (01300)')
|
||||
expect(champ_value_for('engagement')).to eq('on')
|
||||
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
|
||||
expect(champ_value_for('dossier_link')).to eq(dossier_to_link.id.to_s)
|
||||
expect(champ_value_for('piece_justificative')).to be_nil # antivirus hasn't approved the file yet
|
||||
rescue RSpec::Expectations::ExpectationNotMetError => e
|
||||
Rails.logger.debug "Error #{e.message.tr("\n", " ")}, will retry"
|
||||
last_expection_error = e
|
||||
sleep(0.1)
|
||||
retry
|
||||
end
|
||||
rescue Timeout::Error => e
|
||||
raise last_expection_error || e
|
||||
end
|
||||
|
||||
## check data on the gui
|
||||
|
||||
|
@ -435,7 +451,7 @@ describe 'The user' do
|
|||
end
|
||||
|
||||
def champ_value_for(libelle)
|
||||
champs = user_dossier.champs
|
||||
champs = user_dossier.reload.champs
|
||||
champs.find { |c| c.libelle == libelle }.value
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue