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

[588] Intent reminder emails go only to relevant students #599

Open
wants to merge 1 commit 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
4 changes: 3 additions & 1 deletion app/jobs/intent_reminder_job.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

# Job to send intent deadline reminders
class IntentReminderJob < ApplicationJob
queue_as :default
Expand All @@ -7,7 +8,8 @@ class IntentReminderJob < ApplicationJob
#
# @param [Draw] the draw to send reminders in
def perform(draw:)
draw.students.each { |s| send_email(s) }
students = draw.students.where(intent: %w(undeclared))
students.each { |s| send_email(s) }
end

private
Expand Down
13 changes: 10 additions & 3 deletions spec/jobs/intent_reminder_job_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe IntentReminderJob, type: :job do
let(:msg) { instance_spy(ActionMailer::MessageDelivery, deliver_later: 1) }
let(:user) { instance_spy('user') }
let(:draw) { instance_spy('draw', students: [user], intent_deadline: 'date') }
it 'sends intent reminders to all users in the draw' do
let(:draw) { instance_spy('draw', intent_deadline: 'date') }
let(:user) do
instance_spy('user').tap do |u|
allow(draw.students).to receive(:where)
.with(intent: %w(undeclared)).and_return([u])
end
end

it 'sends intent reminders to undeclared users in the draw' do
allow(StudentMailer).to receive(:intent_reminder)
.with(user: user).and_return(msg)
described_class.perform_now(draw: draw)
Expand Down