Past all notification to read when gestionnaire is on back office dossier show

This commit is contained in:
Xavier J 2016-12-27 11:23:19 +01:00
parent cea14845d2
commit 4d765d3b46
3 changed files with 22 additions and 13 deletions

View file

@ -19,6 +19,7 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
def show
create_dossier_facade params[:id]
unless @facade.nil?
@champs_private = @facade.champs_private
@ -27,6 +28,8 @@ class Backoffice::DossiersController < Backoffice::DossiersListController
acc
end
end
Notification.where(dossier_id: params[:id].to_i).update_all already_read: true
end
def filter

View file

@ -21,7 +21,7 @@
%tr.dossier-row{id: "tr_dossier_#{dossier.id}", 'data-dossier_url' => backoffice_dossier_url(id: dossier.id)}
- if smart_listing.name.to_s == 'follow_dossiers'
%td.center
- total_notif = dossier.notifications.count
- total_notif = dossier.notifications.where(already_read: false).count
- if total_notif == 0
.badge.progress-bar-default
= total_notif

View file

@ -38,34 +38,40 @@ describe Backoffice::DossiersController, type: :controller do
end
describe 'GET #show' do
subject { get :show, params: {id: dossier_id} }
context 'gestionnaire is connected' do
before do
sign_in gestionnaire
end
it 'returns http success' do
get :show, params: {id: dossier_id}
expect(response).to have_http_status(200)
expect(subject).to have_http_status(200)
end
describe 'all notifications unread are changed' do
it do
expect(Notification).to receive(:where).with(dossier_id: dossier_id).and_return(Notification::ActiveRecord_Relation)
expect(Notification::ActiveRecord_Relation).to receive(:update_all).with(already_read: true).and_return(true)
subject
end
end
context ' when dossier is archived' do
before do
get :show, params: {id: dossier_archived.id}
end
it { expect(response).to redirect_to('/backoffice') }
let(:dossier_id) { dossier_archived }
it { expect(subject).to redirect_to('/backoffice') }
end
context 'when dossier id does not exist' do
before do
get :show, params: {id: bad_dossier_id}
end
it { expect(response).to redirect_to('/backoffice') }
let(:dossier_id) { bad_dossier_id }
it { expect(subject).to redirect_to('/backoffice') }
end
end
context 'gestionnaire does not connected but dossier id is correct' do
subject { get :show, params: {id: dossier_id} }
it { is_expected.to redirect_to('/gestionnaires/sign_in') }
end
end