Do not send notification email when comments cannot be saved.

This commit is contained in:
Guillaume Lazzara 2016-06-14 16:00:37 +02:00
parent f58f9d27d9
commit 7fd2aa40ca
2 changed files with 15 additions and 2 deletions

View file

@ -22,10 +22,11 @@ class CommentairesController < ApplicationController
end
@commentaire.body = params['texte_commentaire']
@commentaire.save unless flash.alert
saved = false
saved = @commentaire.save unless flash.alert
if is_gestionnaire?
NotificationMailer.new_answer(@commentaire.dossier).deliver_now!
NotificationMailer.new_answer(@commentaire.dossier).deliver_now! if saved
redirect_to url_for(controller: 'backoffice/dossiers', action: :show, id: params['dossier_id'])
elsif current_user.email != @commentaire.dossier.user.email
invite = Invite.where(dossier: @commentaire.dossier, user: current_user).first

View file

@ -91,5 +91,17 @@ describe Backoffice::CommentairesController, type: :controller do
end
end
end
describe 'comment cannot be saved' do
before do
allow_any_instance_of(Commentaire).to receive(:save).and_return(false)
end
it 'Notification email is not sent' do
expect(NotificationMailer).not_to receive(:new_answer)
expect(NotificationMailer).not_to receive(:deliver_now!)
post :create, dossier_id: dossier_id, texte_commentaire: texte_commentaire
end
end
end
end