demarches-normaliennes/spec/mailers/notification_mailer_spec.rb

67 lines
2.4 KiB
Ruby
Raw Normal View History

require "spec_helper"
2015-12-15 11:02:07 +01:00
RSpec.describe NotificationMailer, type: :mailer do
shared_examples_for "create a commentaire not notified" do
it do
expect { subject.deliver_now }.to change { Commentaire.count }.by(1)
subject.deliver_now
commentaire = Commentaire.last
expect(commentaire.body).to include(email_template.subject_for_dossier(dossier), email_template.body_for_dossier(dossier))
expect(commentaire.dossier).to eq(dossier)
end
end
let(:user) { create(:user) }
let(:dossier) { create(:dossier, user: user) }
describe '.send_notification' do
let(:email_template) { instance_double('email_template', subject_for_dossier: 'subject', body_for_dossier: 'body') }
2018-09-05 15:15:16 +02:00
subject(:mail) do
klass = Class.new(described_class) do
# Were testing the (private) method `NotificationMailer#send_notification`.
#
2018-09-05 15:15:37 +02:00
# The standard trick to test a private method would be to `send(:send_notification)`, but doesnt work here,
# because ActionMailer does some magic to expose public instace methods as class methods.
# So, we use inheritance instead to make the private method public for testing purposes.
def send_notification(dossier, template)
super
end
end
klass.send_notification(dossier, email_template)
end
2018-09-05 15:15:16 +02:00
it { expect(mail.subject).to eq(email_template.subject_for_dossier) }
it { expect(mail.body).to include(email_template.body_for_dossier) }
it { expect(mail.body).to have_selector('.footer') }
it_behaves_like "create a commentaire not notified"
end
describe '.send_dossier_received' do
2018-09-05 15:15:16 +02:00
subject(:mail) { described_class.send_dossier_received(dossier) }
let(:email_template) { create(:received_mail) }
before do
dossier.procedure.received_mail = email_template
end
it do
2018-09-05 15:15:16 +02:00
expect(mail.subject).to eq(email_template.subject)
expect(mail.body).to include(email_template.body)
expect(mail.body).to have_selector('.footer')
end
it_behaves_like "create a commentaire not notified"
end
2015-12-15 11:02:07 +01:00
describe ".new_answer" do
subject(:subject) { described_class.new_answer(dossier) }
2018-02-28 16:01:20 +01:00
it { expect(subject.body).to match('Un nouveau message est disponible dans votre espace demarches-simplifiees.fr.') }
2018-09-27 16:32:53 +02:00
it { expect(subject.body).to include(messagerie_dossier_url(dossier)) }
2018-05-31 15:50:13 +02:00
it { expect(subject.subject).to eq("Nouveau message pour votre dossier nº #{dossier.id}") }
2015-12-15 11:02:07 +01:00
end
end