Merge pull request #3656 from betagouv/fix-crash-on-nil-values

Corrige un crash sur des valeurs nulles dans usual_instruction_time
This commit is contained in:
Pierre de La Morinerie 2019-03-25 10:53:31 +01:00 committed by GitHub
commit 5127481cb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View file

@ -467,6 +467,7 @@ class Procedure < ApplicationRecord
def percentile_time(start_attribute, end_attribute, p)
times = dossiers
.where.not(start_attribute => nil, end_attribute => nil)
.where(end_attribute => 1.month.ago..Time.zone.now)
.pluck(start_attribute, end_attribute)
.map { |(start_date, end_date)| end_date - start_date }

View file

@ -780,6 +780,15 @@ describe Procedure do
end
end
context 'when there is a dossier with bad data' do
let(:delays) { [2.days, 2.days] }
let!(:bad_dossier) { create_dossier(instruction_date: nil, processed_date: 10.days.ago) }
it 'ignores bad dossiers' 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(:delays) { [1.day] }
it { expect(procedure.usual_instruction_time).to be_within(10.seconds).of(1.day) }