diff --git a/app/models/member.rb b/app/models/member.rb index d13eac0ec..15ce7c427 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -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 { @@ -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) } diff --git a/spec/models/invitation_manager_spec.rb b/spec/models/invitation_manager_spec.rb index 10235f1f6..4f0553b90 100644 --- a/spec/models/invitation_manager_spec.rb +++ b/spec/models/invitation_manager_spec.rb @@ -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