From 10fee7a12b23a564a3f53cd38a1da4d658f0926a Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 10 Apr 2019 16:03:39 +0200 Subject: [PATCH 1/3] dossiers: decrease estimation cache duration Some badly outdated data where shown to the users. --- app/views/users/dossiers/show/_status_overview.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/dossiers/show/_status_overview.html.haml b/app/views/users/dossiers/show/_status_overview.html.haml index a56294a49..64875b8b3 100644 --- a/app/views/users/dossiers/show/_status_overview.html.haml +++ b/app/views/users/dossiers/show/_status_overview.html.haml @@ -32,7 +32,7 @@ / FIXME: remove the custom procedure switch at some point - if dossier.procedure.usual_verification_time && show_time_means - - cache(dossier.procedure, expires_in: 1.week) do + - cache(dossier.procedure, expires_in: 1.day) do %p Habituellement, les dossiers de cette démarche sont vérifiés dans un délai de #{distance_of_time_in_words(dossier.procedure.usual_verification_time)}. @@ -47,7 +47,7 @@ / FIXME: remove the custom procedure switch at some point - if dossier.procedure.usual_instruction_time && show_time_means - - cache(dossier.procedure, expires_in: 1.week) do + - cache(dossier.procedure, expires_in: 1.day) do %p Habituellement, les dossiers de cette démarche sont traités dans un délai de #{distance_of_time_in_words(dossier.procedure.usual_instruction_time)}. From d855468cb695a196d84c17455fb0ba3883ff0b09 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 10 Apr 2019 16:29:03 +0200 Subject: [PATCH 2/3] dossiers: display the estimate of the entire processing time Displaying separate estimations for en_construction and en_instruction doesn't really make sense for the users: they want to know how long it is going to take overall, not the petty details of our workflow. --- app/models/procedure.rb | 8 --- .../dossiers/show/_estimated_delay.html.haml | 9 +++ .../dossiers/show/_status_overview.html.haml | 19 +----- spec/features/users/dossier_details_spec.rb | 24 +++---- spec/models/procedure_spec.rb | 64 ++++--------------- .../show/_status_overview.html.haml_spec.rb | 4 ++ 6 files changed, 37 insertions(+), 91 deletions(-) create mode 100644 app/views/users/dossiers/show/_estimated_delay.html.haml diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 7c097252f..485ca86c8 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -346,14 +346,6 @@ class Procedure < ApplicationRecord percentile_time(:en_construction_at, :processed_at, 90) end - def usual_verification_time - percentile_time(:en_construction_at, :en_instruction_at, 90) - end - - def usual_instruction_time - percentile_time(:en_instruction_at, :processed_at, 90) - end - PATH_AVAILABLE = :available PATH_AVAILABLE_PUBLIEE = :available_publiee PATH_NOT_AVAILABLE = :not_available diff --git a/app/views/users/dossiers/show/_estimated_delay.html.haml b/app/views/users/dossiers/show/_estimated_delay.html.haml new file mode 100644 index 000000000..d543c3636 --- /dev/null +++ b/app/views/users/dossiers/show/_estimated_delay.html.haml @@ -0,0 +1,9 @@ +/ FIXME: remove the custom procedure switch at some point +- procedure_id_for_which_we_hide_the_estimated_delay = 6547 +- procedure_path_for_which_we_hide_the_estimated_delay = 'deposer-une-offre-de-stage' +- show_time_means = procedure.id != procedure_id_for_which_we_hide_the_estimated_delay && procedure.path != procedure_path_for_which_we_hide_the_estimated_delay + +- if procedure.usual_traitement_time && show_time_means + - cache(procedure, expires_in: 1.day) do + %p + Habituellement, les dossiers de cette démarche sont traités dans un délai de #{distance_of_time_in_words(procedure.usual_traitement_time)}. diff --git a/app/views/users/dossiers/show/_status_overview.html.haml b/app/views/users/dossiers/show/_status_overview.html.haml index 64875b8b3..ceb07234c 100644 --- a/app/views/users/dossiers/show/_status_overview.html.haml +++ b/app/views/users/dossiers/show/_status_overview.html.haml @@ -1,6 +1,4 @@ -- procedure_id_for_which_we_hide_the_time_means = 6547 -- procedure_path_for_which_we_hide_the_time_means = 'deposer-une-offre-de-stage' -- show_time_means = dossier.procedure.id != procedure_id_for_which_we_hide_the_time_means && dossier.procedure.path != procedure_path_for_which_we_hide_the_time_means + .status-overview - if !dossier.termine? @@ -24,17 +22,11 @@ - elsif dossier.en_construction? .en-construction %p Un instructeur de l’administration est en train de vérifier que votre dossier est bien complet. Si des modifications sont nécessaires, vous recevrez un message avec les modifications à effectuer. - %p Sinon, = succeed '.' do %strong votre dossier passera directement en instruction - - / FIXME: remove the custom procedure switch at some point - - if dossier.procedure.usual_verification_time && show_time_means - - cache(dossier.procedure, expires_in: 1.day) do - %p - Habituellement, les dossiers de cette démarche sont vérifiés dans un délai de #{distance_of_time_in_words(dossier.procedure.usual_verification_time)}. + = render partial: 'users/dossiers/show/estimated_delay', locals: { procedure: dossier.procedure } - elsif dossier.en_instruction? .en-instruction @@ -44,12 +36,7 @@ %strong vous recevrez un email avec le résultat. - - / FIXME: remove the custom procedure switch at some point - - if dossier.procedure.usual_instruction_time && show_time_means - - cache(dossier.procedure, expires_in: 1.day) do - %p - Habituellement, les dossiers de cette démarche sont traités dans un délai de #{distance_of_time_in_words(dossier.procedure.usual_instruction_time)}. + = render partial: 'users/dossiers/show/estimated_delay', locals: { procedure: dossier.procedure } - elsif dossier.accepte? .accepte diff --git a/spec/features/users/dossier_details_spec.rb b/spec/features/users/dossier_details_spec.rb index a99ca51be..99332413a 100644 --- a/spec/features/users/dossier_details_spec.rb +++ b/spec/features/users/dossier_details_spec.rb @@ -17,28 +17,24 @@ describe 'Dossier details:' do end describe "the user can see the mean time they are expected to wait" do - context "when the dossier is in construction" do - before do - other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: Time.zone.now) - visit dossier_path(dossier) - end + let(:other_dossier) { create(:dossier, :accepte, :for_individual, procedure: procedure, en_construction_at: 10.days.ago, en_instruction_at: 9.days.ago, processed_at: Time.zone.now) } - it { expect(page).to have_text("Habituellement, les dossiers de cette démarche sont vérifiés dans un délai de 10 jours.") } + context "when the dossier is in construction" do + it "displays the estimated wait duration" do + other_dossier + visit dossier_path(dossier) + expect(page).to have_text("Habituellement, les dossiers de cette démarche sont traités dans un délai de 10 jours.") + end end context "when the dossier is in instruction" do let(:dossier) { create(:dossier, :en_instruction, :for_individual, :with_commentaires, user: user, procedure: procedure) } - before do - Timecop.freeze(Time.zone.local(2012, 12, 20)) - - other_dossier = create(:dossier, :accepte, :for_individual, procedure: procedure, en_instruction_at: 60.days.ago, processed_at: Time.zone.now) + it "displays the estimated wait duration" do + other_dossier visit dossier_path(dossier) + expect(page).to have_text("Habituellement, les dossiers de cette démarche sont traités dans un délai de 10 jours.") end - - after { Timecop.return } - - it { expect(page).to have_text("Habituellement, les dossiers de cette démarche sont traités dans un délai de 2 mois.") } end end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index 7337b1cf5..6652891bc 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -727,59 +727,17 @@ describe Procedure do end end - describe '#usual_verification_time' do + describe '#usual_traitement_time' do let(:procedure) { create(:procedure) } - def create_dossier(construction_date:, instruction_date:) - dossier = create(:dossier, :en_instruction, procedure: procedure) - dossier.update!(en_construction_at: construction_date, en_instruction_at: instruction_date) - end - - before do - delays.each do |delay| - create_dossier(construction_date: 1.week.ago - delay, instruction_date: 1.week.ago) - end - end - - context 'when there are several dossiers in the time frame' do - let(:delays) { [1.day, 2.days, 2.days, 2.days, 2.days, 3.days, 3.days, 3.days, 3.days, 12.days] } - - it 'returns a time representative of the dossier verification delay' do - expect(procedure.usual_verification_time).to be_between(3.days, 4.days) - end - end - - context 'when there are very old dossiers' do - let(:delays) { [2.days, 2.days] } - let!(:old_dossier) { create_dossier(construction_date: 3.months.ago, instruction_date: 2.months.ago) } - - it 'ignores dossiers older than 1 month' do - expect(procedure.usual_verification_time).to be_within(1.hour).of(2.days) - end - end - - context 'when there is only one dossier in the time frame' do - let(:delays) { [1.day] } - it { expect(procedure.usual_verification_time).to be_within(1.hour).of(1.day) } - end - - context 'where there are no dossiers' do - let(:delays) { [] } - it { expect(procedure.usual_verification_time).to be_nil } - end - end - - describe '#usual_instruction_time' do - let(:procedure) { create(:procedure) } - - def create_dossier(instruction_date:, processed_date:) + def create_dossier(construction_date:, instruction_date:, processed_date:) dossier = create(:dossier, :accepte, procedure: procedure) - dossier.update!(en_instruction_at: instruction_date, processed_at: processed_date) + dossier.update!(en_construction_at: construction_date, en_instruction_at: instruction_date, processed_at: processed_date) end before do delays.each do |delay| - create_dossier(instruction_date: 1.week.ago - delay, processed_date: 1.week.ago) + create_dossier(construction_date: 1.week.ago - delay, instruction_date: 1.week.ago - delay + 12.hours, processed_date: 1.week.ago) end end @@ -787,36 +745,36 @@ describe Procedure do let(:delays) { [1.day, 2.days, 2.days, 2.days, 2.days, 3.days, 3.days, 3.days, 3.days, 12.days] } it 'returns a time representative of the dossier instruction delay' do - expect(procedure.usual_instruction_time).to be_between(3.days, 4.days) + expect(procedure.usual_traitement_time).to be_between(3.days, 4.days) end end context 'when there are very old dossiers' do let(:delays) { [2.days, 2.days] } - let!(:old_dossier) { create_dossier(instruction_date: 3.months.ago, processed_date: 2.months.ago) } + let!(:old_dossier) { create_dossier(construction_date: 3.months.ago, instruction_date: 2.months.ago, processed_date: 2.months.ago) } it 'ignores dossiers older than 1 month' do - expect(procedure.usual_instruction_time).to be_within(1.hour).of(2.days) + expect(procedure.usual_traitement_time).to be_within(1.hour).of(2.days) 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) } + let!(:bad_dossier) { create_dossier(construction_date: nil, instruction_date: nil, processed_date: 10.days.ago) } it 'ignores bad dossiers' do - expect(procedure.usual_instruction_time).to be_within(1.hour).of(2.days) + expect(procedure.usual_traitement_time).to be_within(1.hour).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(1.hour).of(1.day) } + it { expect(procedure.usual_traitement_time).to be_within(1.hour).of(1.day) } end context 'where there is no processed dossier' do let(:delays) { [] } - it { expect(procedure.usual_instruction_time).to be_nil } + it { expect(procedure.usual_traitement_time).to be_nil } end end diff --git a/spec/views/users/dossiers/show/_status_overview.html.haml_spec.rb b/spec/views/users/dossiers/show/_status_overview.html.haml_spec.rb index 5e029c883..71362ea7d 100644 --- a/spec/views/users/dossiers/show/_status_overview.html.haml_spec.rb +++ b/spec/views/users/dossiers/show/_status_overview.html.haml_spec.rb @@ -1,4 +1,6 @@ describe 'users/dossiers/show/_status_overview.html.haml', type: :view do + before { allow(dossier.procedure).to receive(:usual_traitement_time).and_return(1.day) } + subject! { render 'users/dossiers/show/status_overview.html.haml', dossier: dossier } matcher :have_timeline_item do |selector| @@ -46,6 +48,7 @@ describe 'users/dossiers/show/_status_overview.html.haml', type: :view do end it { is_expected.to have_selector('.status-explanation .en-construction') } + it { is_expected.to have_text('Habituellement, les dossiers de cette démarche sont traités dans un délai de 1 jour') } end context 'when en instruction' do @@ -59,6 +62,7 @@ describe 'users/dossiers/show/_status_overview.html.haml', type: :view do end it { is_expected.to have_selector('.status-explanation .en-instruction') } + it { is_expected.to have_text('Habituellement, les dossiers de cette démarche sont traités dans un délai de 1 jour') } end context 'when accepté' do From 54813db0ad519c1bc96d8b8e05fc87a7bed3b009 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Wed, 10 Apr 2019 16:58:33 +0200 Subject: [PATCH 3/3] dossiers: fix the cache not actually caching As the expensive `procedure.usual_traitement_time` was called outside of the cache, the cache was useless. --- app/views/users/dossiers/show/_estimated_delay.html.haml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/users/dossiers/show/_estimated_delay.html.haml b/app/views/users/dossiers/show/_estimated_delay.html.haml index d543c3636..2bea129cf 100644 --- a/app/views/users/dossiers/show/_estimated_delay.html.haml +++ b/app/views/users/dossiers/show/_estimated_delay.html.haml @@ -3,7 +3,7 @@ - procedure_path_for_which_we_hide_the_estimated_delay = 'deposer-une-offre-de-stage' - show_time_means = procedure.id != procedure_id_for_which_we_hide_the_estimated_delay && procedure.path != procedure_path_for_which_we_hide_the_estimated_delay -- if procedure.usual_traitement_time && show_time_means - - cache(procedure, expires_in: 1.day) do +- cache(procedure.id, expires_in: 1.day) do + - if procedure.usual_traitement_time && show_time_means %p Habituellement, les dossiers de cette démarche sont traités dans un délai de #{distance_of_time_in_words(procedure.usual_traitement_time)}.