Merge pull request #1926 from internetee/1912-auto-destroy-records-from-bounce-list

Implemented job and test
This commit is contained in:
Timo Võhmar 2021-04-26 18:19:49 +03:00 committed by GitHub
commit 714d0e5530
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,19 @@
class BouncedEmailsCleanerJob < ApplicationJob
queue_as :default
def perform
BouncedMailAddress.find_each do |bounce|
count = Contact.where(email: bounce.email).count
if count.zero?
logger.info "#{bounce.inspect} ARE DELETED!"
bounce.destroy
end
end
end
private
def logger
@logger ||= Rails.logger
end
end

View file

@ -16,6 +16,21 @@ class BouncedMailAddressTest < ActiveSupport::TestCase
@contact_email = "john@inbox.test"
end
def test_remove_bounced_email_after_changed_related_email
@bounced_mail.update(email: @contact_email)
@bounced_mail.save
contacts_with_bounced_mails = Contact.where(email: @contact_email)
contacts_with_bounced_mails.each do |contact|
contact.email = "sara@inbox.com"
contact.save
end
BouncedEmailsCleanerJob.perform_now
assert_nil BouncedMailAddress.find_by(email: @contact_email)
end
def test_soft_force_delete_related_domains
domain_contacts = Contact.where(email: @contact_email).map(&:domain_contacts).flatten