From 43d8db88d973a42d50fa79ce36d3d8b1fdf5ac16 Mon Sep 17 00:00:00 2001 From: Frederic Merizen Date: Fri, 31 Aug 2018 15:44:07 +0200 Subject: [PATCH] =?UTF-8?q?[#1946]=20Check=20if=20a=20dossier=E2=80=99s=20?= =?UTF-8?q?retention=20period=20has=20expired?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/dossier.rb | 10 ++++++++++ spec/models/dossier_spec.rb | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/app/models/dossier.rb b/app/models/dossier.rb index 263609e78..ef4ad39b6 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -183,6 +183,16 @@ class Dossier < ApplicationRecord brouillon? || en_construction? 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 if brouillon? parts = [ diff --git a/spec/models/dossier_spec.rb b/spec/models/dossier_spec.rb index ea60ea3be..f2a1be974 100644 --- a/spec/models/dossier_spec.rb +++ b/spec/models/dossier_spec.rb @@ -1002,4 +1002,30 @@ describe Dossier do it { is_expected.to be false } 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