Skip to content

Commit 6393804

Browse files
committed
Skip students and coaches without TOC accepted
After talking with Kim about this a few weeks ago, we realised it doesn’t make much sense to email members that have not accepted our terms about new events. We see that as not having come back to codebar in a while, thus making more sense to save our resources.
1 parent c6e0a61 commit 6393804

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

app/models/invitation_manager.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ def send_meeting_emails(meeting)
2929

3030
def invite_students_to_event(event, chapter)
3131
chapter_students(chapter).each do |student|
32+
next unless student.accepted_toc_at
33+
3234
invitation = Invitation.new(event: event, member: student, role: 'Student')
3335
EventInvitationMailer.invite_student(event, student, invitation).deliver_now if invitation.save
3436
end
3537
end
3638

3739
def invite_coaches_to_event(event, chapter)
3840
chapter_coaches(chapter).each do |coach|
41+
next unless coach.accepted_toc_at
42+
3943
invitation = Invitation.new(event: event, member: coach, role: 'Coach')
4044
EventInvitationMailer.invite_coach(event, coach, invitation).deliver_now if invitation.save
4145
end

spec/models/invitation_manager_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,52 @@
6666

6767
manager.send_event_emails(event, chapter)
6868
end
69+
70+
it 'emails only students that accepted toc' do
71+
event = Fabricate(:event, chapters: [chapter], audience: 'Students')
72+
73+
first_student, *other_students = students
74+
first_student.update(accepted_toc_at: nil)
75+
76+
expect(Invitation).to_not(
77+
receive(:new).
78+
with(event: event, member: first_student, role: 'Student').
79+
and_call_original
80+
)
81+
82+
other_students.each do |other_student|
83+
expect(Invitation).to(
84+
receive(:new).
85+
with(event: event, member: other_student, role: 'Student').
86+
and_call_original
87+
)
88+
end
89+
90+
manager.send_event_emails(event, chapter)
91+
end
92+
93+
it 'emails only coaches that accepted toc' do
94+
event = Fabricate(:event, chapters: [chapter], audience: 'Coaches')
95+
96+
first_coach, *other_coaches = coaches
97+
first_coach.update(accepted_toc_at: nil)
98+
99+
expect(Invitation).to_not(
100+
receive(:new).
101+
with(event: event, member: first_coach, role: 'Coach').
102+
and_call_original
103+
)
104+
105+
other_coaches.each do |other_coach|
106+
expect(Invitation).to(
107+
receive(:new).
108+
with(event: event, member: other_coach, role: 'Coach').
109+
and_call_original
110+
)
111+
end
112+
113+
manager.send_event_emails(event, chapter)
114+
end
69115
end
70116

71117
describe '#send_monthly_attendance_reminder_emails', wip: true do

0 commit comments

Comments
 (0)