Skip to content

Commit

Permalink
Adoption: Add vaccine reminder mailer (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
garyhtou authored Jul 29, 2023
1 parent 60f1eda commit 54e7282
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/mailers/match_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class MatchMailer < ApplicationMailer
def checklist_reminder(match)
@match = match

@adopter_account = match.adopter_account
@user = @adopter_account.user
@pet = match.pet

mail to: @user.email, subject: "#{@pet.name}'s Checklist Reminder"
end
end
6 changes: 6 additions & 0 deletions app/models/adoption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
class Adoption < ApplicationRecord
belongs_to :pet
belongs_to :adopter_account

after_create_commit :send_checklist_reminder

def send_checklist_reminder
MatchMailer.checklist_reminder(self).deliver_later
end
end
13 changes: 13 additions & 0 deletions app/views/match_mailer/checklist_reminder.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Congrats on <%= @pet.name %>'s adoption!</h1>

<p>Hope everything's going well! This is just a reminder to make sure <%= @pet.name %>'s vaccinations are up to date.</p>

<p>Have a great day!</p>
</body>
</html>
5 changes: 5 additions & 0 deletions app/views/match_mailer/checklist_reminder.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Congrats on <%= @pet.name %>'s adoption!

Hope everything's going well! This is just a reminder to make sure <%= @pet.name %>'s vaccinations are up to date.

Have a great day!
16 changes: 16 additions & 0 deletions test/mailers/match_mailer_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "test_helper"

class MatchMailerTest < ActionMailer::TestCase
test "checklist reminder" do
email = MatchMailer.checklist_reminder(adoptions(:adoption_one))

assert_emails 1 do
email.deliver_now
end

assert_equal [adoptions(:adoption_one).adopter_account.user.email], email.to
assert_match(/Checklist Reminder/, email.subject)
assert_match(/#{adoptions(:adoption_one).pet.name}/, email.subject)
assert_match(/#{adoptions(:adoption_one).pet.name}/, email.body.encoded)
end
end
6 changes: 6 additions & 0 deletions test/mailers/previews/match_mailer_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Preview all emails at http://localhost:3000/rails/mailers/match_mailer
class MatchMailerPreview < ActionMailer::Preview
def checklist_reminder
MatchMailer.checklist_reminder(Adoption.first)
end
end

0 comments on commit 54e7282

Please sign in to comment.