AvisController: add a notification when a avis has been received
This commit is contained in:
parent
34a7905828
commit
cdcd5b951f
4 changed files with 11 additions and 1 deletions
|
@ -24,6 +24,7 @@ class Backoffice::AvisController < ApplicationController
|
|||
|
||||
def update
|
||||
if avis.update(update_params)
|
||||
NotificationService.new('avis', params[:dossier_id]).notify
|
||||
flash[:notice] = 'Merci, votre avis a été enregistré.'
|
||||
end
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ class Notification < ActiveRecord::Base
|
|||
cerfa: 'cerfa',
|
||||
piece_justificative: 'piece_justificative',
|
||||
champs: 'champs',
|
||||
submitted: 'submitted'
|
||||
submitted: 'submitted',
|
||||
avis: 'avis'
|
||||
}
|
||||
scope :unread, -> { where(already_read: false) }
|
||||
end
|
||||
|
|
|
@ -35,6 +35,8 @@ class NotificationService
|
|||
attribut
|
||||
when 'submitted'
|
||||
"Le dossier nº #{@dossier_id} a été déposé."
|
||||
when 'avis'
|
||||
'Un nouvel avis a été rendu'
|
||||
else
|
||||
'Notification par défaut'
|
||||
end
|
||||
|
|
|
@ -39,6 +39,11 @@ describe Backoffice::AvisController, type: :controller do
|
|||
|
||||
subject { post :update, params: { dossier_id: dossier.id, id: avis.id, avis: { answer: "Ok ce dossier est valide." } } }
|
||||
|
||||
before :each do
|
||||
notification = double('notification', notify: true)
|
||||
allow(NotificationService).to receive(:new).and_return(notification)
|
||||
end
|
||||
|
||||
context 'when gestionnaire is not authenticated' do
|
||||
it { is_expected.to redirect_to new_user_session_path }
|
||||
it { expect(avis.answer).to be_nil }
|
||||
|
@ -54,6 +59,7 @@ describe Backoffice::AvisController, type: :controller do
|
|||
it do
|
||||
subject
|
||||
expect(avis.reload.answer).to eq("Ok ce dossier est valide.")
|
||||
expect(NotificationService).to have_received(:new).at_least(:once)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue