only retrieve id of procedures with notifications
This commit is contained in:
parent
d9c7051a00
commit
e4de522b48
3 changed files with 9 additions and 12 deletions
|
@ -144,17 +144,14 @@ class Instructeur < ApplicationRecord
|
|||
.with_notifications(self)
|
||||
end
|
||||
|
||||
def procedures_with_notifications(scope)
|
||||
dossiers = Dossier
|
||||
def procedure_ids_with_notifications(scope)
|
||||
groupe_instructeur_ids = Dossier
|
||||
.send(scope) # :en_cours or :termine (or any other Dossier scope)
|
||||
.merge(followed_dossiers)
|
||||
.with_notifications(self)
|
||||
.select(:groupe_instructeur_id)
|
||||
|
||||
Procedure
|
||||
.where(id: dossiers.joins(:groupe_instructeur)
|
||||
.select('groupe_instructeurs.procedure_id')
|
||||
.distinct)
|
||||
.distinct
|
||||
GroupeInstructeur.where(id: groupe_instructeur_ids).pluck(:procedure_id)
|
||||
end
|
||||
|
||||
def mark_tab_as_seen(dossier, tab)
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
%li
|
||||
%object
|
||||
= link_to(instructeur_procedure_path(p, statut: 'suivis')) do
|
||||
- if current_instructeur.procedures_with_notifications(:en_cours).include?(p)
|
||||
- if current_instructeur.procedure_ids_with_notifications(:en_cours).include?(p.id)
|
||||
%span.notifications{ 'aria-label': "notifications" }
|
||||
- followed_count = followed_dossiers_count_per_procedure[p.id] || 0
|
||||
.stats-number
|
||||
|
@ -31,7 +31,7 @@
|
|||
%li
|
||||
%object
|
||||
= link_to(instructeur_procedure_path(p, statut: 'traites')) do
|
||||
- if current_instructeur.procedures_with_notifications(:termine).include?(p)
|
||||
- if current_instructeur.procedure_ids_with_notifications(:termine).include?(p.id)
|
||||
%span.notifications{ 'aria-label': "notifications" }
|
||||
- termines_count = dossiers_termines_count_per_procedure[p.id] || 0
|
||||
.stats-number
|
||||
|
|
|
@ -352,17 +352,17 @@ describe Instructeur, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#notifications_per_procedure' do
|
||||
describe '#procedure_ids_with_notifications' do
|
||||
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
|
||||
let(:instructeur) { dossier.follows.first.instructeur }
|
||||
let(:procedure) { dossier.procedure }
|
||||
|
||||
subject { instructeur.procedures_with_notifications(:en_cours) }
|
||||
subject { instructeur.procedure_ids_with_notifications(:en_cours) }
|
||||
|
||||
context 'when there is a modification on public champs' do
|
||||
before { dossier.update!(last_champ_updated_at: Time.zone.now) }
|
||||
|
||||
it { is_expected.to match([procedure]) }
|
||||
it { is_expected.to match([procedure.id]) }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue