From 34a7905828f133082be2305095dc927428b43a18 Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Wed, 24 May 2017 17:55:00 +0200 Subject: [PATCH] DossierController: giving an advice does not remove the notifications --- app/controllers/backoffice/dossiers_controller.rb | 6 +++++- spec/controllers/backoffice/dossiers_controller_spec.rb | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/backoffice/dossiers_controller.rb b/app/controllers/backoffice/dossiers_controller.rb index 5c9b7f4ca..8cc2260ae 100644 --- a/app/controllers/backoffice/dossiers_controller.rb +++ b/app/controllers/backoffice/dossiers_controller.rb @@ -32,7 +32,11 @@ class Backoffice::DossiersController < Backoffice::DossiersListController @headers_private = @champs_private.select { |champ| champ.type_champ == 'header_section' } end - Notification.where(dossier_id: dossier_id).update_all already_read: true + # if the current_gestionnaire does not own the dossier, it is here to give an advice + # and it should not remove the notifications + if current_gestionnaire.dossiers.find_by(id: dossier_id).present? + Notification.where(dossier_id: dossier_id).update_all(already_read: true) + end @new_avis = Avis.new(introduction: "Bonjour, merci de me donner votre avis sur ce dossier.") end diff --git a/spec/controllers/backoffice/dossiers_controller_spec.rb b/spec/controllers/backoffice/dossiers_controller_spec.rb index 7a647f51c..a5889ec9f 100644 --- a/spec/controllers/backoffice/dossiers_controller_spec.rb +++ b/spec/controllers/backoffice/dossiers_controller_spec.rb @@ -127,6 +127,13 @@ describe Backoffice::DossiersController, type: :controller do it { expect(subject.status).to eq(200) } it { expect(subject.body).to include("Votre avis est sollicité sur le dossier") } it { expect(subject.body).to_not include("Invitez une personne externe à consulter le dossier et à vous donner un avis sur celui ci.") } + + describe 'the notifications are not marked as read' do + it do + expect(Notification).not_to receive(:where) + subject + end + end end end