From e5ac555a41ca5d96bb4a34e0eef5a62c16c09a79 Mon Sep 17 00:00:00 2001 From: Mathieu Magnin Date: Thu, 11 May 2017 10:15:18 +0200 Subject: [PATCH] fix #245 it should only count dossiers with notifications on followed dossiers --- ...koffice_dossierscontroller_index.html.haml | 2 +- spec/models/gestionnaire_spec.rb | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml index cdbc2b329..320dadc79 100644 --- a/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml +++ b/app/views/layouts/left_panels/_left_panel_backoffice_dossierscontroller_index.html.haml @@ -28,7 +28,7 @@ - if total_new > 0 .badge.progress-bar-success{ title: 'Nouveaux dossiers' } = total_new - - unread_notif_count = procedure.notifications.unread.count + - unread_notif_count = current_gestionnaire.dossier_with_notification_for(procedure) - if unread_notif_count > 0 .badge.progress-bar-warning{ title: 'Notifications' } = unread_notif_count diff --git a/spec/models/gestionnaire_spec.rb b/spec/models/gestionnaire_spec.rb index 9a49c8af4..b3a20f6d6 100644 --- a/spec/models/gestionnaire_spec.rb +++ b/spec/models/gestionnaire_spec.rb @@ -312,4 +312,36 @@ describe Gestionnaire, type: :model do it { is_expected.to eq(2) } end end + + describe '#dossier_with_notification_for' do + subject { gestionnaire.dossier_with_notification_for(procedure) } + + context 'without notifications' do + it { is_expected.to eq(0) } + end + + context 'with a followed dossier' do + let!(:dossier){create(:dossier, procedure: procedure, state: 'received')} + let!(:follow){ create(:follow, dossier: dossier, gestionnaire: gestionnaire) } + + context 'with 1 notification' do + let!(:notification){ create(:notification, already_read: false, dossier: dossier) } + + it { is_expected.to eq(1) } + end + + context 'with 1 read notification' do + let!(:notification){ create(:notification, already_read: true, dossier: dossier) } + + it { is_expected.to eq(0) } + end + + context 'with 2 notification' do + let!(:notification){ create(:notification, already_read: false, dossier: dossier) } + let!(:notification2){ create(:notification, already_read: false, dossier: dossier) } + + it { is_expected.to eq(1) } + end + end + end end