Email notification: use the right method for procedures

This commit is contained in:
simon lehericey 2019-04-17 15:20:10 +02:00
parent 176be142cc
commit e65e21a72f
3 changed files with 7 additions and 5 deletions

View file

@ -127,6 +127,8 @@ class Gestionnaire < ApplicationRecord
procedure.dossiers.termine
when :not_archived
procedure.dossiers.not_archived
when :all
procedure.dossiers
else
procedure.dossiers.en_cours
end
@ -226,7 +228,7 @@ class Gestionnaire < ApplicationRecord
h = {
nb_en_construction: procedure.dossiers.en_construction.count,
nb_notification: notifications_per_procedure(procedure).count
nb_notification: notifications_for_procedure(procedure, :all).count
}
if h[:nb_en_construction] > 0 || h[:nb_notification] > 0

View file

@ -279,7 +279,7 @@ describe Gestionnaire, type: :model do
end
end
describe '#notification_for_procedure' do
describe '#notifications_for_procedure' do
let!(:dossier) { create(:dossier, :followed, state: Dossier.states.fetch(:en_construction)) }
let(:gestionnaire) { dossier.follows.first.gestionnaire }
let(:procedure) { dossier.procedure }
@ -438,8 +438,8 @@ describe Gestionnaire, type: :model do
context 'when a notification exists' do
before do
allow(gestionnaire).to receive(:notifications_per_procedure)
.with(procedure_to_assign)
allow(gestionnaire).to receive(:notifications_for_procedure)
.with(procedure_to_assign, :all)
.and_return([1, 2, 3])
end

View file

@ -49,7 +49,7 @@ describe NotificationService do
context 'when there is a notification on this procedure' do
before do
allow_any_instance_of(Gestionnaire).to receive(:notifications_per_procedure)
allow_any_instance_of(Gestionnaire).to receive(:notifications_for_procedure)
.and_return([12])
end