2017-03-15 12:40:59 +01:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2017-10-03 16:19:25 +02:00
|
|
|
RSpec.describe AutoArchiveProcedureJob, type: :job do
|
2018-05-17 15:43:33 +02:00
|
|
|
let!(:procedure) { create(:procedure, :published, auto_archive_on: nil) }
|
|
|
|
let!(:procedure_hier) { create(:procedure, :published, auto_archive_on: 1.day.ago) }
|
|
|
|
let!(:procedure_aujourdhui) { create(:procedure, :published, auto_archive_on: Date.today) }
|
|
|
|
let!(:procedure_demain) { create(:procedure, :published, auto_archive_on: 1.day.from_now) }
|
2017-03-15 12:40:59 +01:00
|
|
|
|
2017-10-03 16:19:25 +02:00
|
|
|
subject { AutoArchiveProcedureJob.new.perform }
|
2017-03-15 12:40:59 +01:00
|
|
|
|
|
|
|
context "when procedures have no auto_archive_on" do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
procedure.reload
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:09:25 +02:00
|
|
|
it { expect(procedure.archivee?).to eq false }
|
2017-03-15 12:40:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when procedures have auto_archive_on set on yesterday or today" do
|
2018-01-15 21:54:40 +01:00
|
|
|
let!(:dossier1) { create(:dossier, procedure: procedure_hier, state: 'brouillon', archived: false) }
|
|
|
|
let!(:dossier2) { create(:dossier, procedure: procedure_hier, state: 'en_construction', archived: false) }
|
|
|
|
let!(:dossier3) { create(:dossier, procedure: procedure_hier, state: 'en_construction', archived: false) }
|
|
|
|
let!(:dossier4) { create(:dossier, procedure: procedure_hier, state: 'en_construction', archived: false) }
|
|
|
|
let!(:dossier5) { create(:dossier, procedure: procedure_hier, state: 'en_instruction', archived: false) }
|
|
|
|
let!(:dossier6) { create(:dossier, procedure: procedure_hier, state: 'accepte', archived: false) }
|
|
|
|
let!(:dossier7) { create(:dossier, procedure: procedure_hier, state: 'refuse', archived: false) }
|
|
|
|
let!(:dossier8) { create(:dossier, procedure: procedure_hier, state: 'sans_suite', archived: false) }
|
|
|
|
let!(:dossier9) { create(:dossier, procedure: procedure_aujourdhui, state: 'en_construction', archived: false) }
|
2017-03-15 12:40:59 +01:00
|
|
|
|
2017-06-29 12:20:27 +02:00
|
|
|
before do
|
|
|
|
subject
|
2017-06-29 15:07:33 +02:00
|
|
|
|
2018-03-06 11:53:26 +01:00
|
|
|
[dossier1, dossier2, dossier3, dossier4, dossier5, dossier6, dossier7, dossier8, dossier9].each(&:reload)
|
2017-06-29 15:07:33 +02:00
|
|
|
|
2017-06-29 12:20:27 +02:00
|
|
|
procedure_hier.reload
|
|
|
|
procedure_aujourdhui.reload
|
2017-03-15 12:40:59 +01:00
|
|
|
end
|
2017-06-29 12:20:27 +02:00
|
|
|
|
2017-12-04 16:17:15 +01:00
|
|
|
it { expect(dossier1.state).to eq 'brouillon' }
|
2017-12-14 15:53:02 +01:00
|
|
|
it { expect(dossier2.state).to eq 'en_instruction' }
|
|
|
|
it { expect(dossier3.state).to eq 'en_instruction' }
|
|
|
|
it { expect(dossier4.state).to eq 'en_instruction' }
|
|
|
|
it { expect(dossier5.state).to eq 'en_instruction' }
|
2017-12-04 18:00:12 +01:00
|
|
|
it { expect(dossier6.state).to eq 'accepte' }
|
2017-12-04 18:15:40 +01:00
|
|
|
it { expect(dossier7.state).to eq 'refuse' }
|
2017-12-04 20:23:57 +01:00
|
|
|
it { expect(dossier8.state).to eq 'sans_suite' }
|
2017-12-14 15:53:02 +01:00
|
|
|
it { expect(dossier9.state).to eq 'en_instruction' }
|
2017-06-29 12:20:27 +02:00
|
|
|
|
2017-07-13 15:09:25 +02:00
|
|
|
it { expect(procedure_hier.archivee?).to eq true }
|
|
|
|
it { expect(procedure_aujourdhui.archivee?).to eq true }
|
2017-03-15 12:40:59 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
context "when procedures have auto_archive_on set on future" do
|
|
|
|
before do
|
|
|
|
subject
|
|
|
|
end
|
|
|
|
|
2017-07-13 15:09:25 +02:00
|
|
|
it { expect(procedure_demain.archivee?).to eq false }
|
2017-03-15 12:40:59 +01:00
|
|
|
end
|
|
|
|
end
|