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 <paul.chavard@beta.gouv.fr>

Update spec/controllers/instructeurs/dossiers_controller_spec.rb

Co-authored-by: Paul Chavard <paul.chavard@beta.gouv.fr>
This commit is contained in:
Martin 2022-04-06 15:05:03 +02:00 committed by mfo
parent a9769ae277
commit 9bac5c65ba
2 changed files with 4 additions and 1 deletions

View file

@ -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)

View file

@ -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