diff --git a/spec/factories/dossier.rb b/spec/factories/dossier.rb index 8c2fe14fa..7449915f8 100644 --- a/spec/factories/dossier.rb +++ b/spec/factories/dossier.rb @@ -80,7 +80,7 @@ FactoryBot.define do trait :en_construction do after(:create) do |dossier, _evaluator| dossier.state = Dossier.states.fetch(:en_construction) - dossier.en_construction_at = dossier.created_at + 1.minute + dossier.en_construction_at ||= dossier.created_at + 1.minute dossier.save! end end @@ -88,8 +88,8 @@ FactoryBot.define do trait :en_instruction do after(:create) do |dossier, _evaluator| dossier.state = Dossier.states.fetch(:en_instruction) - dossier.en_construction_at = dossier.created_at + 1.minute - dossier.created_at = dossier.created_at + 2.minutes + dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute dossier.save! end end @@ -97,9 +97,9 @@ FactoryBot.define do trait :accepte do after(:create) do |dossier, _evaluator| dossier.state = Dossier.states.fetch(:accepte) - dossier.processed_at ||= dossier.created_at + 1.minute - dossier.en_construction_at ||= dossier.created_at + 2.minutes - dossier.created_at ||= dossier.created_at + 3.minutes + dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute + dossier.processed_at ||= dossier.en_instruction_at + 1.minute dossier.save! end end @@ -107,9 +107,9 @@ FactoryBot.define do trait :refuse do after(:create) do |dossier, _evaluator| dossier.state = Dossier.states.fetch(:refuse) - dossier.processed_at = dossier.created_at + 1.minute - dossier.en_construction_at = dossier.created_at + 2.minutes - dossier.created_at = dossier.created_at + 3.minutes + dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute + dossier.processed_at ||= dossier.en_instruction_at + 1.minute dossier.save! end end @@ -117,9 +117,9 @@ FactoryBot.define do trait :sans_suite do after(:create) do |dossier, _evaluator| dossier.state = Dossier.states.fetch(:sans_suite) - dossier.processed_at = dossier.created_at + 1.minute - dossier.en_construction_at = dossier.created_at + 2.minutes - dossier.created_at = dossier.created_at + 3.minutes + dossier.en_construction_at ||= dossier.created_at + 1.minute + dossier.en_instruction_at ||= dossier.en_construction_at + 1.minute + dossier.processed_at ||= dossier.en_instruction_at + 1.minute dossier.save! end end diff --git a/spec/jobs/auto_receive_dossiers_for_procedure_job_spec.rb b/spec/jobs/auto_receive_dossiers_for_procedure_job_spec.rb index 953b00a87..e7fa7b6f4 100644 --- a/spec/jobs/auto_receive_dossiers_for_procedure_job_spec.rb +++ b/spec/jobs/auto_receive_dossiers_for_procedure_job_spec.rb @@ -3,6 +3,7 @@ require 'rails_helper' RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do describe "perform" do let(:date) { Time.utc(2017, 9, 1, 10, 5, 0) } + let(:instruction_date) { date + 120 } before do Timecop.freeze(date) @@ -28,7 +29,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do it { expect(nouveau_dossier2.reload.en_instruction_at).to eq(date) } it { expect(dossier_recu.reload.en_instruction?).to be true } - it { expect(dossier_recu.reload.en_instruction_at).to eq(date) } + it { expect(dossier_recu.reload.en_instruction_at).to eq(instruction_date) } it { expect(dossier_brouillon.reload.brouillon?).to be true } it { expect(dossier_brouillon.reload.en_instruction_at).to eq(nil) } @@ -46,7 +47,7 @@ RSpec.describe AutoReceiveDossiersForProcedureJob, type: :job do it { expect(nouveau_dossier2.reload.processed_at).to eq(date) } it { expect(dossier_recu.reload.en_instruction?).to be true } - it { expect(dossier_recu.reload.en_instruction_at).to eq(date) } + it { expect(dossier_recu.reload.en_instruction_at).to eq(instruction_date) } it { expect(dossier_recu.reload.processed_at).to eq(nil) } it { expect(dossier_brouillon.reload.brouillon?).to be true }