procedure: compute the usual instruction time only for the last month

This commit is contained in:
Pierre de La Morinerie 2018-11-13 15:21:15 +00:00
parent b693e055b7
commit 83031b5cdd
2 changed files with 10 additions and 0 deletions

View file

@ -426,6 +426,7 @@ class Procedure < ApplicationRecord
def percentile_time(start_attribute, end_attribute, p)
times = dossiers
.state_termine
.where(end_attribute => 1.month.ago..DateTime.current)
.pluck(start_attribute, end_attribute)
.map { |(start_date, end_date)| end_date - start_date }

View file

@ -727,6 +727,15 @@ describe Procedure do
end
end
context 'when there are very old dossiers' do
let(:processed_delays) { [2.days, 2.days] }
let!(:old_dossier) { create_dossier(instruction_date: 3.months.ago, processed_date: 2.months.ago) }
it 'ignores dossiers older than 1 month' do
expect(procedure.usual_instruction_time).to be_within(10.seconds).of(2.days)
end
end
context 'when there is only one processed dossier' do
let(:processed_delays) { [1.day] }
it { expect(procedure.usual_instruction_time).to be_within(10.seconds).of(1.day) }