From 65d399b4b0539e9194d9450afe7199f1160a3d3b Mon Sep 17 00:00:00 2001 From: Simon Lehericey Date: Sun, 5 Mar 2017 20:20:29 +0100 Subject: [PATCH] NotificationMailer: add send notification --- app/mailers/notification_mailer.rb | 9 +++++++++ spec/mailers/notification_mailer_spec.rb | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 4e2d78d5f..068e8ae27 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -2,6 +2,15 @@ class NotificationMailer < ApplicationMailer default from: 'tps@apientreprise.fr', to: Proc.new { @user.email } + def send_notification dossier, email + vars_mailer(dossier) + + obj = email.object_for_dossier dossier + body = email.body_for_dossier dossier + + mail(subject: obj) { |format| format.html { body } } + end + def new_answer dossier send_mail dossier, "Nouveau message pour votre dossier TPS N°#{dossier.id}" end diff --git a/spec/mailers/notification_mailer_spec.rb b/spec/mailers/notification_mailer_spec.rb index 10d6b5e24..9abd89322 100644 --- a/spec/mailers/notification_mailer_spec.rb +++ b/spec/mailers/notification_mailer_spec.rb @@ -1,6 +1,16 @@ require "spec_helper" RSpec.describe NotificationMailer, type: :mailer do + describe '.send_notification' do + let(:user) { create(:user) } + let(:dossier) { create(:dossier, user: user) } + let(:email) { instance_double('email', object_for_dossier: 'object', body_for_dossier: 'body') } + subject { described_class.send_notification(dossier, email) } + + it { expect(subject.subject).to eq(email.object_for_dossier) } + it { expect(subject.body).to eq(email.body_for_dossier) } + end + describe ".new_answer" do let(:user) { create(:user) } let(:dossier) { create(:dossier, user: user) }