Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop emailing students & coaches without TOC accepted #1750

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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