Explicitly pass the “state” param in notifications_*_procedure methods
This commit is contained in:
parent
8a06c01f13
commit
769621de46
4 changed files with 13 additions and 13 deletions
|
@ -109,29 +109,29 @@ class Instructeur < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def notifications_for_procedure(procedure, state = :en_cours)
|
||||
def notifications_for_procedure(procedure, state)
|
||||
dossiers = case state
|
||||
when :en_cours
|
||||
procedure.defaut_groupe_instructeur.dossiers.en_cours
|
||||
when :termine
|
||||
procedure.defaut_groupe_instructeur.dossiers.termine
|
||||
when :not_archived
|
||||
procedure.defaut_groupe_instructeur.dossiers.not_archived
|
||||
when :all
|
||||
procedure.defaut_groupe_instructeur.dossiers
|
||||
else
|
||||
procedure.defaut_groupe_instructeur.dossiers.en_cours
|
||||
end
|
||||
|
||||
dossiers_id_with_notifications(dossiers)
|
||||
end
|
||||
|
||||
def notifications_per_procedure(state = :en_cours)
|
||||
def notifications_per_procedure(state)
|
||||
dossiers = case state
|
||||
when :en_cours
|
||||
Dossier.en_cours
|
||||
when :termine
|
||||
Dossier.termine
|
||||
when :not_archived
|
||||
Dossier.not_archived
|
||||
else
|
||||
Dossier.en_cours
|
||||
end
|
||||
|
||||
Dossier.joins(:groupe_instructeur).where(id: dossiers_id_with_notifications(dossiers)).group('groupe_instructeurs.procedure_id').count
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
%li
|
||||
%object
|
||||
= link_to(instructeur_procedure_path(p, statut: 'suivis')) do
|
||||
- if current_instructeur.notifications_per_procedure[p.id].present?
|
||||
- if current_instructeur.notifications_per_procedure(:en_cours)[p.id].present?
|
||||
%span.notifications{ 'aria-label': "notifications" }
|
||||
- followed_count = @followed_dossiers_count_per_procedure[p.id] || 0
|
||||
.stats-number
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
instructeur_procedure_path(@procedure, statut: 'suivis'),
|
||||
active: @statut == 'suivis',
|
||||
badge: @followed_dossiers.count,
|
||||
notification: current_instructeur.notifications_for_procedure(@procedure).present?)
|
||||
notification: current_instructeur.notifications_for_procedure(@procedure, :en_cours).present?)
|
||||
|
||||
= tab_item(t('pluralize.processed', count: @termines_dossiers.count),
|
||||
instructeur_procedure_path(@procedure, statut: 'traites'),
|
||||
|
|
|
@ -248,7 +248,7 @@ describe Instructeur, type: :model do
|
|||
instructeur_2.followed_dossiers << dossier
|
||||
end
|
||||
|
||||
subject { instructeur.notifications_for_procedure(procedure) }
|
||||
subject { instructeur.notifications_for_procedure(procedure, :en_cours) }
|
||||
|
||||
context 'when the instructeur has just followed the dossier' do
|
||||
it { is_expected.to match([]) }
|
||||
|
@ -258,8 +258,8 @@ describe Instructeur, type: :model do
|
|||
before { dossier.champs.first.update_attribute('value', 'toto') }
|
||||
|
||||
it { is_expected.to match([dossier.id]) }
|
||||
it { expect(instructeur_2.notifications_for_procedure(procedure)).to match([dossier.id]) }
|
||||
it { expect(instructeur_on_procedure_2.notifications_for_procedure(procedure)).to match([]) }
|
||||
it { expect(instructeur_2.notifications_for_procedure(procedure, :en_cours)).to match([dossier.id]) }
|
||||
it { expect(instructeur_on_procedure_2.notifications_for_procedure(procedure, :en_cours)).to match([]) }
|
||||
|
||||
context 'and there is a modification on private champs' do
|
||||
before { dossier.champs_private.first.update_attribute('value', 'toto') }
|
||||
|
@ -273,7 +273,7 @@ describe Instructeur, type: :model do
|
|||
before { follow.update_attribute('demande_seen_at', Time.zone.now) }
|
||||
|
||||
it { is_expected.to match([]) }
|
||||
it { expect(instructeur_2.notifications_for_procedure(procedure)).to match([dossier.id]) }
|
||||
it { expect(instructeur_2.notifications_for_procedure(procedure, :en_cours)).to match([dossier.id]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -315,7 +315,7 @@ describe Instructeur, type: :model do
|
|||
let(:instructeur) { dossier.follows.first.instructeur }
|
||||
let(:procedure) { dossier.procedure }
|
||||
|
||||
subject { instructeur.notifications_per_procedure }
|
||||
subject { instructeur.notifications_per_procedure(:en_cours) }
|
||||
|
||||
context 'when there is a modification on public champs' do
|
||||
before { dossier.champs.first.update_attribute('value', 'toto') }
|
||||
|
|
Loading…
Reference in a new issue