The BulletproofMailer class in lib/bulletproof_mailer.rb was originally introduced to allow emails to be cancelled by calling abort_delivery, which throws an error and prevents an email from being sent. But as redsummernight points out, this workaround is no longer necessary in the current version of Rails.
To modernize the handling of aborted emails and clean up the codebase, it would be nice to make the following changes:
Update UserMailer to extend ActionMailer::Base instead of BulletMailer::Base.
Update UserMailer#batch_subscription_notification to use return instead of abort_delivery.
Testing Instructions: We need to make sure that subscription notifications can be cancelled. Specifically:
Log in as User A.
Subscribe to User B.
Log in as User B.
Post a new work.
Immediately after posting, edit the work and add it to an Anonymous collection.
Wait for subscription notifications to be sent, and make sure that User A didn't receive an email.
Check Resque to make sure that the subscription notification didn't produce a failed job.
Subscribed to my main account using an alt.
Posted a work as my main, edited to make anonymous: https://test.archiveofourown.org/works/1071095.
Posted a work as my main, left not anonymous for comparison. ETA: deleted the not-anonymous work on my main. UserMailer#batch_subscription_notification should be aborted correctly.
The subscription email task runs every hour. I received emails for other subscriptions, but not for the aforementioned subscription to my main. https://test.archiveofourown.org/resque/overview listed no failed jobs.
For testing this one properly, you actually can’t post a work that will send a subscription email in the same period. The point is to check that it can abort the email properly, and it’ll only abort the email if there’s nothing to notify about.
EDIT: To clarify, it doesn’t have to be that there are no subscription emails whatsoever. Just that the same user doesn’t post any works that would send out subscription emails during that period.
Subscribed to myself, posted a work, edited the work to add it to an anon collection, went on console and sent subscription emails because I’m impatient. Didn’t get an email. Checked Resque and there was no failed job.