From 64c964bf5e043eb1fe8f4e755eec2c81845fbecc Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Wed, 11 Nov 2020 15:40:44 +0100 Subject: [PATCH 1/2] fix broken nil values in france_connect_informatio --- .../_france_connect_informations.html.haml | 6 +++- ...ance_connect_information.html.haml_spec.rb | 32 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb diff --git a/app/views/shared/dossiers/_france_connect_informations.html.haml b/app/views/shared/dossiers/_france_connect_informations.html.haml index ba7256521..b875f26b4 100644 --- a/app/views/shared/dossiers/_france_connect_informations.html.haml +++ b/app/views/shared/dossiers/_france_connect_informations.html.haml @@ -1,4 +1,8 @@ .card.featured .flex.justify-center = image_tag "logo-france-connect.png", alt: "France Connect logo", width: 200, class: "mb-2" - .card-title Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}, authentifié par France Connect le #{user_information.updated_at.strftime('%d/%m/%Y')}. + .card-title + - if user_information.updated_at.present? + Le dossier a été déposé par le compte de #{user_information&.given_name} #{user_information&.family_name}, authentifié par France Connect le #{user_information.updated_at.strftime('%d/%m/%Y')}. + - else + Le dossier a été déposé par le compte de #{user_information&.given_name} #{user_information&.family_name}. diff --git a/spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb b/spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb new file mode 100644 index 000000000..1d8f76e16 --- /dev/null +++ b/spec/views/shared/dossiers/_france_connect_information.html.haml_spec.rb @@ -0,0 +1,32 @@ +describe 'shared/dossiers/france_connect_informations.html.haml', type: :view do + subject do + render( + 'shared/dossiers/france_connect_informations.html.haml', + user_information: user_information + ) + end + + context "with complete france_connect information" do + let(:user_information) { build(:france_connect_information, updated_at: Time.zone.now) } + it { + expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}, authentifié par France Connect le #{user_information.updated_at.strftime('%d/%m/%Y')}") + } + end + + context "with missing updated_at" do + let(:user_information) { build(:france_connect_information, updated_at: nil) } + + it { + expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.given_name} #{user_information.family_name}") + expect(subject).not_to have_text("authentifié par France Connect le ") + } + end + + context "with missing given_name" do + let(:user_information) { build(:france_connect_information, given_name: nil) } + + it { + expect(subject).to have_text("Le dossier a été déposé par le compte de #{user_information.family_name}") + } + end +end From dae65c49f66732c6070009c711ef866857de8f64 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Wed, 11 Nov 2020 16:40:55 +0100 Subject: [PATCH 2/2] revert counters display in Instructeur::ProceduresController::show, we recently used a grouped query for counters for some reason, this grouped query in procedure#dossiers_count_for_instructeur gives incorrect results. I keep this method as is for now (instructeurs are complaining) and hotfix the controllers --- .../instructeurs/procedures_controller.rb | 1 - app/views/instructeurs/procedures/show.html.haml | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/app/controllers/instructeurs/procedures_controller.rb b/app/controllers/instructeurs/procedures_controller.rb index 67d13b647..aca2ddbe9 100644 --- a/app/controllers/instructeurs/procedures_controller.rb +++ b/app/controllers/instructeurs/procedures_controller.rb @@ -102,7 +102,6 @@ module Instructeurs @has_termine_notifications = current_instructeur.notifications_for_procedure(@procedure, :termine).exists? @not_archived_notifications_dossier_ids = current_instructeur.notifications_for_procedure(@procedure, :not_archived).pluck(:id) - @counters = @procedure.dossiers_count_for_instructeur(current_instructeur) sorted_ids = procedure_presentation.sorted_ids(@dossiers, current_instructeur) diff --git a/app/views/instructeurs/procedures/show.html.haml b/app/views/instructeurs/procedures/show.html.haml index b425fe13a..f8f4b395f 100644 --- a/app/views/instructeurs/procedures/show.html.haml +++ b/app/views/instructeurs/procedures/show.html.haml @@ -24,29 +24,29 @@ = tab_item('à suivre', instructeur_procedure_path(@procedure, statut: 'a-suivre'), active: @statut == 'a-suivre', - badge: number_with_html_delimiter(@counters['a_suivre'])) + badge: number_with_html_delimiter(@a_suivre_dossiers.count)) - = tab_item(t('pluralize.followed', count: @counters['suivis']), + = tab_item(t('pluralize.followed', count: @followed_dossiers.count), instructeur_procedure_path(@procedure, statut: 'suivis'), active: @statut == 'suivis', - badge: number_with_html_delimiter(@counters['suivis']), + badge: number_with_html_delimiter(@followed_dossiers.count), notification: @has_en_cours_notifications) - = tab_item(t('pluralize.processed', count: @counters['termines']), + = tab_item(t('pluralize.processed', count: @termines_dossiers.count), instructeur_procedure_path(@procedure, statut: 'traites'), active: @statut == 'traites', - badge: number_with_html_delimiter(@counters['termines']), + badge: number_with_html_delimiter(@termines_dossiers.count), notification: @has_termine_notifications) = tab_item('tous les dossiers', instructeur_procedure_path(@procedure, statut: 'tous'), active: @statut == 'tous', - badge: number_with_html_delimiter(@counters['total'])) + badge: number_with_html_delimiter(@all_state_dossiers.count)) = tab_item(t('pluralize.archived', count: @archived_dossiers.count), instructeur_procedure_path(@procedure, statut: 'archives'), active: @statut == 'archives', - badge: number_with_html_delimiter(@counters['archived'])) + badge: number_with_html_delimiter(@archived_dossiers.count)) .procedure-actions = render partial: "download_dossiers",