Add scheduled email feature for reminders

This commit is contained in:
2020-02-12 14:19:27 +01:00
parent e4a317111c
commit 9ee37b42d8
13 changed files with 127 additions and 4 deletions

View File

@ -0,0 +1,7 @@
# Preview all emails at http://localhost:3000/rails/mailers/reminder_mailer
class ReminderMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/reminder_mailer/schedule_email
def schedule_email
ReminderMailer.schedule_email(FactoryBot.build(:reminder), 'to@example.com')
end
end

View File

@ -0,0 +1,29 @@
require 'rails_helper'
RSpec.describe ReminderMailer, type: :mailer do
describe 'Email delivery' do
let(:reminder) { build :reminder }
let(:mail) { ReminderMailer.schedule_email reminder, 'to@example.org' }
it 'renders the headers' do
expect(mail.subject).to eq 'Reminder'
expect(mail.to).to eq ['to@example.org']
expect(mail.from).to eq ['from@example.com']
end
it 'renders the body' do
expect(mail.body.encoded).to have_content reminder.title
expect(mail.body.encoded).to have_content reminder.body
end
end
describe 'Scheduled email' do
before { clear_enqueued_jobs }
let(:reminder) { create :reminder }
it 'queues the reminder' do
expect { ReminderMailer.schedule_email(reminder, 'to@example.org').deliver_later(wait_until: reminder.date) }.to have_enqueued_job.on_queue('mailers')
expect { ReminderMailer.schedule_email(reminder, 'to@example.org').deliver_later(wait_until: reminder.date) }.to have_enqueued_job.at(reminder.date)
end
end
end