Merge pull request #273 from sgmap/fix_notifications_count

Fix notifications count
This commit is contained in:
Mathieu Magnin 2017-05-12 10:26:46 +02:00 committed by GitHub
commit 503f174f4b
2 changed files with 40 additions and 1 deletions

View file

@ -28,7 +28,7 @@
- if total_new > 0
.badge.progress-bar-success{ title: 'Nouveaux dossiers' }
= total_new
- unread_notif_count = procedure.notifications.unread.count
- unread_notif_count = current_gestionnaire.dossier_with_notification_for(procedure)
- if unread_notif_count > 0
.badge.progress-bar-warning{ title: 'Notifications' }
= unread_notif_count

View file

@ -288,6 +288,13 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq(1) }
end
context 'when there is one notification read' do
let(:notification){ create(:notification, already_read: true) }
let!(:follow){ create(:follow, dossier: notification.dossier, gestionnaire: gestionnaire) }
it { is_expected.to eq(0) }
end
context 'when there are many notifications for one dossier' do
let(:notification){ create(:notification, already_read: false) }
let(:notification2){ create(:notification, already_read: false, dossier: notification.dossier) }
@ -305,4 +312,36 @@ describe Gestionnaire, type: :model do
it { is_expected.to eq(2) }
end
end
describe '#dossier_with_notification_for' do
subject { gestionnaire.dossier_with_notification_for(procedure) }
context 'without notifications' do
it { is_expected.to eq(0) }
end
context 'with a followed dossier' do
let!(:dossier){create(:dossier, procedure: procedure, state: 'received')}
let!(:follow){ create(:follow, dossier: dossier, gestionnaire: gestionnaire) }
context 'with 1 notification' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
it { is_expected.to eq(1) }
end
context 'with 1 read notification' do
let!(:notification){ create(:notification, already_read: true, dossier: dossier) }
it { is_expected.to eq(0) }
end
context 'with 2 notification' do
let!(:notification){ create(:notification, already_read: false, dossier: dossier) }
let!(:notification2){ create(:notification, already_read: false, dossier: dossier) }
it { is_expected.to eq(1) }
end
end
end
end