Skip to content

Commit

Permalink
Merge pull request #1750 from gnclmorais/dont-email-unaccepted-toc
Browse files Browse the repository at this point in the history
Stop emailing students & coaches without TOC accepted
  • Loading branch information
gnclmorais authored Oct 26, 2024
2 parents c6e0a61 + 2eddf9d commit 5b641f3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/models/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Member < ApplicationRecord
validates :email, uniqueness: true
validates :about_you, length: { maximum: 255 }

scope :accepted_toc, -> { where.not(accepted_toc_at: nil) }
scope :order_by_email, -> { order(:email) }
scope :subscribers, -> { joins(:subscriptions).order('created_at desc').uniq }
scope :not_banned, lambda {
Expand All @@ -32,7 +33,9 @@ class Member < ApplicationRecord
.where('meeting_invitations.meeting_id = ? and meeting_invitations.attending = ?',
meeting.id, true)
}
scope :in_group, ->(members) { not_banned.joins(:groups).where(groups: { id: members.select(:id) }) }
scope :in_group, lambda { |members|
not_banned.accepted_toc.joins(:groups).where(groups: { id: members.select(:id) })
}

scope :with_skill, ->(skill_name) { tagged_with(skill_name) }

Expand Down
46 changes: 46 additions & 0 deletions spec/models/invitation_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,52 @@

manager.send_event_emails(event, chapter)
end

it 'emails only students that accepted toc' do
event = Fabricate(:event, chapters: [chapter], audience: 'Students')

first_student, *other_students = students
first_student.update(accepted_toc_at: nil)

expect(Invitation).to_not(
receive(:new).
with(event: event, member: first_student, role: 'Student').
and_call_original
)

other_students.each do |other_student|
expect(Invitation).to(
receive(:new).
with(event: event, member: other_student, role: 'Student').
and_call_original
)
end

manager.send_event_emails(event, chapter)
end

it 'emails only coaches that accepted toc' do
event = Fabricate(:event, chapters: [chapter], audience: 'Coaches')

first_coach, *other_coaches = coaches
first_coach.update(accepted_toc_at: nil)

expect(Invitation).to_not(
receive(:new).
with(event: event, member: first_coach, role: 'Coach').
and_call_original
)

other_coaches.each do |other_coach|
expect(Invitation).to(
receive(:new).
with(event: event, member: other_coach, role: 'Coach').
and_call_original
)
end

manager.send_event_emails(event, chapter)
end
end

describe '#send_monthly_attendance_reminder_emails', wip: true do
Expand Down

0 comments on commit 5b641f3

Please sign in to comment.