[#1946] Check if a dossier’s retention period has expired
This commit is contained in:
parent
b672377f5b
commit
43d8db88d9
2 changed files with 36 additions and 0 deletions
|
@ -183,6 +183,16 @@ class Dossier < ApplicationRecord
|
||||||
brouillon? || en_construction?
|
brouillon? || en_construction?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def retention_end_date
|
||||||
|
if instruction_commencee?
|
||||||
|
en_instruction_at + procedure.duree_conservation_dossiers_dans_ds.months
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def retention_expired?
|
||||||
|
instruction_commencee? && retention_end_date <= DateTime.now
|
||||||
|
end
|
||||||
|
|
||||||
def text_summary
|
def text_summary
|
||||||
if brouillon?
|
if brouillon?
|
||||||
parts = [
|
parts = [
|
||||||
|
|
|
@ -1002,4 +1002,30 @@ describe Dossier do
|
||||||
it { is_expected.to be false }
|
it { is_expected.to be false }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "retention date" do
|
||||||
|
let(:procedure) { create(:procedure, duree_conservation_dossiers_dans_ds: 6) }
|
||||||
|
let(:uninstructed_dossier) { create(:dossier, :en_construction, procedure: procedure) }
|
||||||
|
let(:young_dossier) { create(:dossier, :en_instruction, en_instruction_at: DateTime.now, procedure: procedure) }
|
||||||
|
let(:just_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 6.months.ago, procedure: procedure) }
|
||||||
|
let(:long_expired_dossier) { create(:dossier, :en_instruction, en_instruction_at: 1.year.ago, procedure: procedure) }
|
||||||
|
let(:modif_date) { DateTime.parse('01/01/2100') }
|
||||||
|
|
||||||
|
before { Timecop.freeze(modif_date) }
|
||||||
|
after { Timecop.return }
|
||||||
|
|
||||||
|
describe "#retention_end_date" do
|
||||||
|
it { expect(uninstructed_dossier.retention_end_date).to be_nil }
|
||||||
|
it { expect(young_dossier.retention_end_date).to eq(6.months.from_now) }
|
||||||
|
it { expect(just_expired_dossier.retention_end_date).to eq(DateTime.now) }
|
||||||
|
it { expect(long_expired_dossier.retention_end_date).to eq(6.months.ago) }
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#retention_expired?" do
|
||||||
|
it { expect(uninstructed_dossier).not_to be_retention_expired }
|
||||||
|
it { expect(young_dossier).not_to be_retention_expired }
|
||||||
|
it { expect(just_expired_dossier).to be_retention_expired }
|
||||||
|
it { expect(long_expired_dossier).to be_retention_expired }
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue