Merge pull request #280 from sgmap/fix-198
[Fix #198] Add a Commentaire when we send a Notification email to a user
This commit is contained in:
commit
339b8791f1
2 changed files with 26 additions and 3 deletions
|
@ -1,13 +1,15 @@
|
||||||
class NotificationMailer < ApplicationMailer
|
class NotificationMailer < ApplicationMailer
|
||||||
default to: Proc.new { @user.email }
|
default to: Proc.new { @user.email }
|
||||||
|
|
||||||
|
after_action :create_commentaire_for_notification, only: :send_notification
|
||||||
|
|
||||||
def send_notification dossier, mail_template
|
def send_notification dossier, mail_template
|
||||||
vars_mailer(dossier)
|
vars_mailer(dossier)
|
||||||
|
|
||||||
obj = mail_template.object_for_dossier dossier
|
@obj = mail_template.object_for_dossier dossier
|
||||||
body = mail_template.body_for_dossier dossier
|
@body = mail_template.body_for_dossier dossier
|
||||||
|
|
||||||
mail(subject: obj) { |format| format.html { body } }
|
mail(subject: @obj) { |format| format.html { @body } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_answer dossier
|
def new_answer dossier
|
||||||
|
@ -16,6 +18,14 @@ class NotificationMailer < ApplicationMailer
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def create_commentaire_for_notification
|
||||||
|
Commentaire.create(
|
||||||
|
dossier: @dossier,
|
||||||
|
email: "contact@tps.apientreprise.fr",
|
||||||
|
body: ["[#{@obj}]", @body].join("<br><br>")
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def vars_mailer dossier
|
def vars_mailer dossier
|
||||||
@dossier = dossier
|
@dossier = dossier
|
||||||
@user = dossier.user
|
@user = dossier.user
|
||||||
|
|
|
@ -5,10 +5,23 @@ RSpec.describe NotificationMailer, type: :mailer do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
let(:dossier) { create(:dossier, user: user) }
|
let(:dossier) { create(:dossier, user: user) }
|
||||||
let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') }
|
let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') }
|
||||||
|
let (:notifications_count_before) { Notification.count }
|
||||||
subject { described_class.send_notification(dossier, email) }
|
subject { described_class.send_notification(dossier, email) }
|
||||||
|
|
||||||
it { expect(subject.subject).to eq(email.object_for_dossier) }
|
it { expect(subject.subject).to eq(email.object_for_dossier) }
|
||||||
it { expect(subject.body).to eq(email.body_for_dossier) }
|
it { expect(subject.body).to eq(email.body_for_dossier) }
|
||||||
|
|
||||||
|
it "creates a commentaire, which is not notified" do
|
||||||
|
described_class.send_notification(dossier, email).deliver_now
|
||||||
|
|
||||||
|
commentaire = Commentaire.last
|
||||||
|
notifications_count_after = Notification.count
|
||||||
|
|
||||||
|
expect(commentaire.dossier).to eq(dossier)
|
||||||
|
expect(commentaire.email).to eq("contact@tps.apientreprise.fr")
|
||||||
|
expect(commentaire.body).to eq("[object]<br><br>body")
|
||||||
|
expect(notifications_count_before).to eq(notifications_count_after)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe ".new_answer" do
|
describe ".new_answer" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue