Merge pull request #6282 from betagouv/fix-flaky-traitement-spec
Tests : correction de l'usage de `Timecop.freeze` dans les tests de Traitement (#6282)
This commit is contained in:
commit
a3c7de6e45
1 changed files with 13 additions and 8 deletions
|
@ -2,23 +2,27 @@ describe Traitement do
|
||||||
describe '#count_dossiers_termines_by_month' do
|
describe '#count_dossiers_termines_by_month' do
|
||||||
let(:procedure) { create(:procedure, :published, groupe_instructeurs: [groupe_instructeurs]) }
|
let(:procedure) { create(:procedure, :published, groupe_instructeurs: [groupe_instructeurs]) }
|
||||||
let(:groupe_instructeurs) { create(:groupe_instructeur) }
|
let(:groupe_instructeurs) { create(:groupe_instructeur) }
|
||||||
let(:result) { Traitement.count_dossiers_termines_by_month(groupe_instructeurs) }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create_dossier_for_month(procedure, 2021, 3)
|
create_dossier_for_month(procedure, 2021, 3)
|
||||||
create_dossier_for_month(procedure, 2021, 3)
|
create_dossier_for_month(procedure, 2021, 3)
|
||||||
create_dossier_for_month(procedure, 2021, 2)
|
create_dossier_for_month(procedure, 2021, 2)
|
||||||
Timecop.freeze(Time.zone.local(2021, 3, 5))
|
end
|
||||||
|
|
||||||
|
subject do
|
||||||
|
Timecop.freeze(Time.zone.local(2021, 3, 5)) do
|
||||||
|
Traitement.count_dossiers_termines_by_month(groupe_instructeurs)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'count dossiers_termines by month' do
|
it 'count dossiers_termines by month' do
|
||||||
expect(count_for_month(result, 3)).to eq 2
|
expect(count_for_month(subject, 3)).to eq 2
|
||||||
expect(count_for_month(result, 2)).to eq 1
|
expect(count_for_month(subject, 2)).to eq 1
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns descending order by month' do
|
it 'returns descending order by month' do
|
||||||
expect(result[0]["month"].to_date.month).to eq 3
|
expect(subject[0]["month"].to_date.month).to eq 3
|
||||||
expect(result[1]["month"].to_date.month).to eq 2
|
expect(subject[1]["month"].to_date.month).to eq 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -31,7 +35,8 @@ describe Traitement do
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_dossier_for_month(procedure, year, month)
|
def create_dossier_for_month(procedure, year, month)
|
||||||
Timecop.freeze(Time.zone.local(year, month, 5))
|
Timecop.freeze(Time.zone.local(year, month, 5)) do
|
||||||
create(:dossier, :accepte, :with_attestation, procedure: procedure)
|
create(:dossier, :accepte, :with_attestation, procedure: procedure)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue