Merge pull request #2700 from betagouv/fix_2696_mean_instruction_time

Fix 2696 mean instruction time
This commit is contained in:
LeSim 2018-09-27 15:32:10 +02:00 committed by GitHub
commit b0bca99d9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 1 deletions

View file

@ -405,7 +405,7 @@ class Procedure < ApplicationRecord
times = dossiers
.state_termine
.pluck(start_attribute, end_attribute)
.map { |times| times[1] - times[0] }
.map { |(start_date, end_date)| end_date - start_date }
if times.present?
times.sum.fdiv(times.size).ceil

View file

@ -0,0 +1,9 @@
namespace :'2018_09_27_fill_missing_en_instruction_at' do
task run: :environment do
dossiers_with_missing_instruction_at = Dossier
.where.not(processed_at: nil)
.where(en_instruction_at: nil)
dossiers_with_missing_instruction_at.each { |d| d.update(en_instruction_at: d.processed_at) }
end
end

View file

@ -773,4 +773,23 @@ describe Procedure do
expect(p.juridique_required).to be_truthy
end
end
describe '#mean_instruction_time' do
let(:procedure) { create(:procedure) }
context 'when there is only one dossier' do
let(:dossier) { create(:dossier, procedure: procedure) }
context 'which is termine' do
before do
dossier.accepte!
processed_date = DateTime.parse('12/12/2012')
instruction_date = processed_date - 1.day
dossier.update(en_instruction_at: instruction_date, processed_at: processed_date)
end
it { expect(procedure.mean_instruction_time).to eq(1.day.to_i) }
end
end
end
end