Skip to content
Merged
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
1 change: 1 addition & 0 deletions app/services/gpo_reminder_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def send_emails(for_letters_sent_before)
reminder_eligible_range =
IdentityConfig.store.usps_confirmation_max_days.days.ago..for_letters_sent_before
profiles_due_for_reminder(for_letters_sent_before).each do |profile|
next if profile.user.active_profile
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I spent a few minutes trying to adjust the ActiveRecord query to just find profiles for users that don't have an active profile, but gave up and went with this. The numbers are pretty small in production, so there's not too much associated waste with doing this filtering in Ruby code rather than in SQL.

profile.gpo_confirmation_codes.all.each do |gpo_code|
next if gpo_code.reminder_sent_at
next unless reminder_eligible_range.cover?(gpo_code.created_at)
Expand Down
10 changes: 10 additions & 0 deletions spec/jobs/gpo_reminder_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,15 @@
user_id: due_for_reminder_user.uuid,
)
end

context 'when the user has another active profile' do
let!(:active_profile) do
create(:profile, :active, user: due_for_reminder_user)
end

it 'does not send an email' do
expect { perform }.not_to change { ActionMailer::Base.deliveries.count }
end
end
end
end