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:
commit
5127481cb1
2 changed files with 10 additions and 0 deletions
|
@ -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 }
|
||||
|
|
|
@ -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) }
|
||||
|
|
Loading…
Reference in a new issue