From a9769ae277cae3e779d73db5c3433dd191831b8a Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 6 Apr 2022 15:01:07 +0200 Subject: [PATCH 1/2] fix(instructeur/dossiers#create_avis): as an instructeur, when I ask an avis, i hope to be notified when the expert give his avis --- spec/controllers/instructeurs/dossiers_controller_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index bd3c80f20..c0642a768 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -509,6 +509,13 @@ describe Instructeurs::DossiersController, type: :controller do end end + context 'as an instructeur, i auto follow the dossier so I get the notifications' do + it 'works' do + subject + expect(instructeur.follows.where(dossier: dossier).count).to eq(1) + end + end + context 'email sending' do before do subject From 9bac5c65bafef1ce1e2f076a73e2eac19159ed14 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 6 Apr 2022 15:05:03 +0200 Subject: [PATCH 2/2] feat(instructeurs/dossier#create_avis): only followed dossier receive notifications, so when an instructeur ask for an avis, he follows the dossier Update app/controllers/concerns/create_avis_concern.rb Co-authored-by: Paul Chavard Update spec/controllers/instructeurs/dossiers_controller_spec.rb Co-authored-by: Paul Chavard --- app/controllers/concerns/create_avis_concern.rb | 3 +++ spec/controllers/instructeurs/dossiers_controller_spec.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/controllers/concerns/create_avis_concern.rb b/app/controllers/concerns/create_avis_concern.rb index 8b7e55865..74965976c 100644 --- a/app/controllers/concerns/create_avis_concern.rb +++ b/app/controllers/concerns/create_avis_concern.rb @@ -17,6 +17,9 @@ module CreateAvisConcern allowed_dossiers += dossier.linked_dossiers_for(instructeur_or_expert) end + if (instructeur_or_expert.is_a?(Instructeur)) && !instructeur_or_expert.follows.exists?(dossier: dossier) + instructeur_or_expert.follow(dossier) + end create_results = Avis.create( expert_emails.flat_map do |email| user = User.create_or_promote_to_expert(email, SecureRandom.hex) diff --git a/spec/controllers/instructeurs/dossiers_controller_spec.rb b/spec/controllers/instructeurs/dossiers_controller_spec.rb index c0642a768..4962ac9d4 100644 --- a/spec/controllers/instructeurs/dossiers_controller_spec.rb +++ b/spec/controllers/instructeurs/dossiers_controller_spec.rb @@ -512,7 +512,7 @@ describe Instructeurs::DossiersController, type: :controller do context 'as an instructeur, i auto follow the dossier so I get the notifications' do it 'works' do subject - expect(instructeur.follows.where(dossier: dossier).count).to eq(1) + expect(instructeur.followed_dossiers).to match_array([dossier]) end end