Add scheduled email feature for reminders
This commit is contained in:
7
spec/mailers/previews/reminder_mailer_preview.rb
Normal file
7
spec/mailers/previews/reminder_mailer_preview.rb
Normal 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
|
29
spec/mailers/reminder_mailer_spec.rb
Normal file
29
spec/mailers/reminder_mailer_spec.rb
Normal 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
|
Reference in New Issue
Block a user