AvisController: add a notification when a avis has been received

This commit is contained in:
Simon Lehericey 2017-05-22 17:10:17 +02:00
parent 34a7905828
commit cdcd5b951f
4 changed files with 11 additions and 1 deletions

View file

@ -24,6 +24,7 @@ class Backoffice::AvisController < ApplicationController
def update def update
if avis.update(update_params) if avis.update(update_params)
NotificationService.new('avis', params[:dossier_id]).notify
flash[:notice] = 'Merci, votre avis a été enregistré.' flash[:notice] = 'Merci, votre avis a été enregistré.'
end end

View file

@ -5,7 +5,8 @@ class Notification < ActiveRecord::Base
cerfa: 'cerfa', cerfa: 'cerfa',
piece_justificative: 'piece_justificative', piece_justificative: 'piece_justificative',
champs: 'champs', champs: 'champs',
submitted: 'submitted' submitted: 'submitted',
avis: 'avis'
} }
scope :unread, -> { where(already_read: false) } scope :unread, -> { where(already_read: false) }
end end

View file

@ -35,6 +35,8 @@ class NotificationService
attribut attribut
when 'submitted' when 'submitted'
"Le dossier nº #{@dossier_id} a été déposé." "Le dossier nº #{@dossier_id} a été déposé."
when 'avis'
'Un nouvel avis a été rendu'
else else
'Notification par défaut' 'Notification par défaut'
end end

View file

@ -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." } } } 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 context 'when gestionnaire is not authenticated' do
it { is_expected.to redirect_to new_user_session_path } it { is_expected.to redirect_to new_user_session_path }
it { expect(avis.answer).to be_nil } it { expect(avis.answer).to be_nil }
@ -54,6 +59,7 @@ describe Backoffice::AvisController, type: :controller do
it do it do
subject subject
expect(avis.reload.answer).to eq("Ok ce dossier est valide.") expect(avis.reload.answer).to eq("Ok ce dossier est valide.")
expect(NotificationService).to have_received(:new).at_least(:once)
end end
end end