Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/jobs/send_three_month_email_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class SendThreeMonthEmailJob < ApplicationJob
queue_as :default

def perform
ThreeMonthEmailService.send_chaser
end
end
19 changes: 19 additions & 0 deletions app/mailers/concerns/email_delivery.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module EmailDelivery
extend ActiveSupport::Concern

private

def log_sent_email
member = params[:member]
return unless member

MemberEmailDelivery.create!(
member: member,
subject: mail.subject,
body: mail.body.to_s,
to: mail.to,
cc: mail.cc,
bcc: mail.bcc
)
end
end
11 changes: 11 additions & 0 deletions app/mailers/member_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
class MemberMailer < ApplicationMailer
include EmailHeaderHelper
include EmailDelivery

after_action :log_sent_email, only: [:chaser]

def chaser
@member = params[:member]
subject = "It’s been a while, how are you doing? ♥️"
mail mail_args(@member, subject, '[email protected]', '[email protected]') do |format|
format.html {render 'three_month_chaser'}
end
end

def welcome(member)
if member.student?
Expand Down
3 changes: 3 additions & 0 deletions app/models/member_email_delivery.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class MemberEmailDelivery < ApplicationRecord
belongs_to :member, polymorphic: true, optional: true
end
10 changes: 10 additions & 0 deletions app/services/three_month_email_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class ThreeMonthEmailService
def self.send_chaser
members = Member.joins(:workshop_invitations).where("workshop_invitations.create_at >= ?", 3.months.ago).distinct
members.each do |member|
MemberMailer.with(member: member).chaser.deliver_later
end
end
end
21 changes: 21 additions & 0 deletions app/views/member_mailer/three_month_chaser.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
%h1 Hi #{@member.name},

%p
We’ve noticed you haven’t been to a codebar workshop in a little while, and we just wanted to check in. We know life gets busy, but we’d love to understand how things are going for you and whether there’s anything we can do to make it easier or more valuable for you to join again.
%p
If you have a minute, could you please share your thoughts in this short form? 👉 https://forms.gle/tEETvC3zYP9mcLar7

%p
Or, if you’re thinking about coming back soon, we’ve got some great upcoming workshops and events you might like to join 👉https://codebar.io/events/

%p
Your feedback really helps us make codebar more welcoming and useful for everyone in our community 💜

%p
We’d love to see you again soon!

%p
#{"-- "}
%br
Warmly,
The Codebar Team
3 changes: 3 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class Application < Rails::Application

config.active_record.belongs_to_required_by_default = true

# let's start using Active Job!
config.active_job.queue_adapter = :delayed_job

if ENV["RAILS_LOG_TO_STDOUT"].present?
$stdout.sync = true
config.rails_semantic_logger.add_file_appender = false
Expand Down
17 changes: 17 additions & 0 deletions spec/mailers/member_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,21 @@
end.to change { ActionMailer::Base.deliveries.count }.by 1
end
end

describe "#chaser" do
it "logs the sent email" do
expect do
MemberMailer
.with(member: member)
.chaser
.deliver_now
end.to change(MemberEmailDelivery, :count).by(1)

log = MemberEmailDelivery.last
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: When looking up records with #first or #last, and you expect there to be a record, prefer the exception-raising #first! and #last!. Those exceptions are even clearer signals, crashing earlier than "NoMethodError nil does not respond to #member".

You're making nice tests!


expect(log.member).to eq(member)
expect(log.subject).to eq("It’s been a while, how are you doing? ♥️")
expect(log.to).to eq([member.email])
end
end
end
Loading