Merge pull request #1006 from sgmap/improve_tests_reliability
Tests: add (or group) Timecop.return to resume time in specs
This commit is contained in:
commit
2a5f92ffaf
8 changed files with 21 additions and 33 deletions
|
@ -12,6 +12,8 @@ describe Admin::AttestationTemplatesController, type: :controller do
|
|||
Timecop.freeze(Time.now)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
describe 'POST #preview' do
|
||||
let(:upload_params) { { title: 't', body: 'b', footer: 'f' } }
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ describe StatsController, type: :controller do
|
|||
FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 1.hour.ago)
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
|
||||
let (:association) { Procedure.all }
|
||||
|
||||
context "while a super admin is logged in" do
|
||||
|
@ -85,8 +87,6 @@ describe StatsController, type: :controller do
|
|||
})
|
||||
}
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
end
|
||||
|
||||
describe "#procedures_count_per_administrateur" do
|
||||
|
@ -230,9 +230,8 @@ describe StatsController, type: :controller do
|
|||
let!(:avis_with_dossier) { create(:avis) }
|
||||
let!(:dossier2) { create(:dossier) }
|
||||
|
||||
before do
|
||||
Timecop.freeze(Time.now)
|
||||
end
|
||||
before { Timecop.freeze(Time.now) }
|
||||
after { Timecop.return }
|
||||
|
||||
subject { StatsController.new.send(:avis_usage) }
|
||||
|
||||
|
@ -271,9 +270,8 @@ describe StatsController, type: :controller do
|
|||
|
||||
subject { StatsController.new.send(:avis_answer_percentages) }
|
||||
|
||||
before do
|
||||
Timecop.freeze(Time.now)
|
||||
end
|
||||
before { Timecop.freeze(Time.now) }
|
||||
after { Timecop.return }
|
||||
|
||||
it { is_expected.to match [[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 66.67]] }
|
||||
end
|
||||
|
@ -283,9 +281,8 @@ describe StatsController, type: :controller do
|
|||
let!(:dossier2) { create(:dossier, processed_at: 1.week.ago) }
|
||||
let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) }
|
||||
|
||||
before do
|
||||
Timecop.freeze(Time.now)
|
||||
end
|
||||
before { Timecop.freeze(Time.now) }
|
||||
after { Timecop.return }
|
||||
|
||||
subject { StatsController.new.send(:motivation_usage_dossier) }
|
||||
|
||||
|
@ -298,9 +295,8 @@ describe StatsController, type: :controller do
|
|||
let!(:dossier2) { create(:dossier, processed_at: 1.week.ago) }
|
||||
let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) }
|
||||
|
||||
before do
|
||||
Timecop.freeze(Time.now)
|
||||
end
|
||||
before { Timecop.freeze(Time.now) }
|
||||
after { Timecop.return }
|
||||
|
||||
subject { StatsController.new.send(:motivation_usage_procedure) }
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
|
|||
let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) }
|
||||
|
||||
before { Timecop.freeze(date) }
|
||||
after { Timecop.return }
|
||||
|
||||
subject { AutoReceiveDossiersForProcedureJob.new.perform(procedure_id) }
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ describe AttestationTemplate, type: :model do
|
|||
after do
|
||||
@logo.close
|
||||
@signature.close
|
||||
Timecop.return
|
||||
end
|
||||
|
||||
let(:view_args) do
|
||||
|
|
|
@ -892,6 +892,7 @@ describe Dossier do
|
|||
let(:modif_date) { DateTime.parse('01/01/2100') }
|
||||
|
||||
before { Timecop.freeze(modif_date) }
|
||||
after { Timecop.return }
|
||||
|
||||
subject do
|
||||
dossier.reload
|
||||
|
@ -941,8 +942,6 @@ describe Dossier do
|
|||
|
||||
it { is_expected.to eq(modif_date) }
|
||||
end
|
||||
|
||||
after { Timecop.return }
|
||||
end
|
||||
|
||||
describe '#owner_name' do
|
||||
|
|
|
@ -314,10 +314,7 @@ describe Gestionnaire, type: :model do
|
|||
let(:friday) { DateTime.new(2017, 5, 12) }
|
||||
let(:monday) { DateTime.now.beginning_of_week }
|
||||
|
||||
before :each do
|
||||
Timecop.freeze(friday)
|
||||
end
|
||||
|
||||
before { Timecop.freeze(friday) }
|
||||
after { Timecop.return }
|
||||
|
||||
context 'when no procedure published was active last week' do
|
||||
|
@ -563,10 +560,9 @@ describe Gestionnaire, type: :model do
|
|||
Timecop.freeze(freeze_date)
|
||||
gestionnaire.mark_tab_as_seen(dossier, :demande)
|
||||
end
|
||||
after { Timecop.return }
|
||||
|
||||
it { expect(follow.demande_seen_at).to eq(freeze_date) }
|
||||
|
||||
after { Timecop.return }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,9 +5,8 @@ describe ProcedureOverview, type: :model do
|
|||
let(:friday) { DateTime.new(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai
|
||||
let(:monday) { DateTime.new(2017, 5, 8) }
|
||||
|
||||
before :each do
|
||||
Timecop.freeze(friday)
|
||||
end
|
||||
before { Timecop.freeze(friday) }
|
||||
after { Timecop.return }
|
||||
|
||||
let(:procedure_overview) { ProcedureOverview.new(procedure, monday) }
|
||||
|
||||
|
|
|
@ -237,16 +237,13 @@ describe Procedure do
|
|||
Timecop.freeze(now)
|
||||
procedure.publish!("example-path")
|
||||
end
|
||||
after { Timecop.return }
|
||||
|
||||
it { expect(procedure.archived_at).to eq(nil) }
|
||||
it { expect(procedure.published_at).to eq(now) }
|
||||
it { expect(ProcedurePath.find_by_path("example-path")).to be }
|
||||
it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) }
|
||||
it { expect(ProcedurePath.find_by_path("example-path").administrateur).to eq(procedure.administrateur) }
|
||||
|
||||
after do
|
||||
Timecop.return
|
||||
end
|
||||
end
|
||||
|
||||
describe "#brouillon?" do
|
||||
|
@ -300,13 +297,10 @@ describe Procedure do
|
|||
procedure.archive
|
||||
procedure.reload
|
||||
end
|
||||
after { Timecop.return }
|
||||
|
||||
it { expect(procedure.archivee?).to be_truthy }
|
||||
it { expect(procedure.archived_at).to eq(now) }
|
||||
|
||||
after do
|
||||
Timecop.return
|
||||
end
|
||||
end
|
||||
|
||||
describe 'total_dossier' do
|
||||
|
|
Loading…
Reference in a new issue