Tests: add (or group) Timecop.return to resume time in specs

This commit is contained in:
Simon Lehericey 2017-11-29 16:07:39 +01:00
parent aa33cb9470
commit d90e22e332
8 changed files with 21 additions and 33 deletions

View file

@ -12,6 +12,8 @@ describe Admin::AttestationTemplatesController, type: :controller do
Timecop.freeze(Time.now) Timecop.freeze(Time.now)
end end
after { Timecop.return }
describe 'POST #preview' do describe 'POST #preview' do
let(:upload_params) { { title: 't', body: 'b', footer: 'f' } } let(:upload_params) { { title: 't', body: 'b', footer: 'f' } }

View file

@ -59,6 +59,8 @@ describe StatsController, type: :controller do
FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 1.hour.ago) FactoryGirl.create(:procedure, :created_at => 15.days.ago, :updated_at => 1.hour.ago)
end end
after { Timecop.return }
let (:association) { Procedure.all } let (:association) { Procedure.all }
context "while a super admin is logged in" do context "while a super admin is logged in" do
@ -85,8 +87,6 @@ describe StatsController, type: :controller do
}) })
} }
end end
after { Timecop.return }
end end
describe "#procedures_count_per_administrateur" do describe "#procedures_count_per_administrateur" do
@ -230,9 +230,8 @@ describe StatsController, type: :controller do
let!(:avis_with_dossier) { create(:avis) } let!(:avis_with_dossier) { create(:avis) }
let!(:dossier2) { create(:dossier) } let!(:dossier2) { create(:dossier) }
before do before { Timecop.freeze(Time.now) }
Timecop.freeze(Time.now) after { Timecop.return }
end
subject { StatsController.new.send(:avis_usage) } subject { StatsController.new.send(:avis_usage) }
@ -271,9 +270,8 @@ describe StatsController, type: :controller do
subject { StatsController.new.send(:avis_answer_percentages) } subject { StatsController.new.send(:avis_answer_percentages) }
before do before { Timecop.freeze(Time.now) }
Timecop.freeze(Time.now) after { Timecop.return }
end
it { is_expected.to match [[3.week.ago.to_i, 0], [2.week.ago.to_i, 0], [1.week.ago.to_i, 66.67]] } 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 end
@ -283,9 +281,8 @@ describe StatsController, type: :controller do
let!(:dossier2) { create(:dossier, processed_at: 1.week.ago) } let!(:dossier2) { create(:dossier, processed_at: 1.week.ago) }
let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) } let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) }
before do before { Timecop.freeze(Time.now) }
Timecop.freeze(Time.now) after { Timecop.return }
end
subject { StatsController.new.send(:motivation_usage_dossier) } 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!(:dossier2) { create(:dossier, processed_at: 1.week.ago) }
let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) } let!(:dossier3) { create(:dossier, processed_at: 1.week.ago) }
before do before { Timecop.freeze(Time.now) }
Timecop.freeze(Time.now) after { Timecop.return }
end
subject { StatsController.new.send(:motivation_usage_procedure) } subject { StatsController.new.send(:motivation_usage_procedure) }

View file

@ -5,6 +5,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do
let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) } let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) }
before { Timecop.freeze(date) } before { Timecop.freeze(date) }
after { Timecop.return }
subject { AutoReceiveDossiersForProcedureJob.new.perform(procedure_id) } subject { AutoReceiveDossiersForProcedureJob.new.perform(procedure_id) }

View file

@ -122,6 +122,7 @@ describe AttestationTemplate, type: :model do
after do after do
@logo.close @logo.close
@signature.close @signature.close
Timecop.return
end end
let(:view_args) do let(:view_args) do

View file

@ -892,6 +892,7 @@ describe Dossier do
let(:modif_date) { DateTime.parse('01/01/2100') } let(:modif_date) { DateTime.parse('01/01/2100') }
before { Timecop.freeze(modif_date) } before { Timecop.freeze(modif_date) }
after { Timecop.return }
subject do subject do
dossier.reload dossier.reload
@ -941,8 +942,6 @@ describe Dossier do
it { is_expected.to eq(modif_date) } it { is_expected.to eq(modif_date) }
end end
after { Timecop.return }
end end
describe '#owner_name' do describe '#owner_name' do

View file

@ -314,10 +314,7 @@ describe Gestionnaire, type: :model do
let(:friday) { DateTime.new(2017, 5, 12) } let(:friday) { DateTime.new(2017, 5, 12) }
let(:monday) { DateTime.now.beginning_of_week } let(:monday) { DateTime.now.beginning_of_week }
before :each do before { Timecop.freeze(friday) }
Timecop.freeze(friday)
end
after { Timecop.return } after { Timecop.return }
context 'when no procedure published was active last week' do context 'when no procedure published was active last week' do
@ -563,10 +560,9 @@ describe Gestionnaire, type: :model do
Timecop.freeze(freeze_date) Timecop.freeze(freeze_date)
gestionnaire.mark_tab_as_seen(dossier, :demande) gestionnaire.mark_tab_as_seen(dossier, :demande)
end end
after { Timecop.return }
it { expect(follow.demande_seen_at).to eq(freeze_date) } it { expect(follow.demande_seen_at).to eq(freeze_date) }
after { Timecop.return }
end end
end end
end end

View file

@ -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(:friday) { DateTime.new(2017, 5, 12) } # vendredi 12 mai 2017, de la semaine du 8 mai
let(:monday) { DateTime.new(2017, 5, 8) } let(:monday) { DateTime.new(2017, 5, 8) }
before :each do before { Timecop.freeze(friday) }
Timecop.freeze(friday) after { Timecop.return }
end
let(:procedure_overview) { ProcedureOverview.new(procedure, monday) } let(:procedure_overview) { ProcedureOverview.new(procedure, monday) }

View file

@ -237,16 +237,13 @@ describe Procedure do
Timecop.freeze(now) Timecop.freeze(now)
procedure.publish!("example-path") procedure.publish!("example-path")
end end
after { Timecop.return }
it { expect(procedure.archived_at).to eq(nil) } it { expect(procedure.archived_at).to eq(nil) }
it { expect(procedure.published_at).to eq(now) } 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")).to be }
it { expect(ProcedurePath.find_by_path("example-path").procedure).to eq(procedure) } 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) } it { expect(ProcedurePath.find_by_path("example-path").administrateur).to eq(procedure.administrateur) }
after do
Timecop.return
end
end end
describe "#brouillon?" do describe "#brouillon?" do
@ -300,13 +297,10 @@ describe Procedure do
procedure.archive procedure.archive
procedure.reload procedure.reload
end end
after { Timecop.return }
it { expect(procedure.archivee?).to be_truthy } it { expect(procedure.archivee?).to be_truthy }
it { expect(procedure.archived_at).to eq(now) } it { expect(procedure.archived_at).to eq(now) }
after do
Timecop.return
end
end end
describe 'total_dossier' do describe 'total_dossier' do