mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 06:34:46 +02:00
Add email verification rake task for one domain only
This commit is contained in:
parent
b4369bdcd0
commit
57cd588eee
3 changed files with 29 additions and 1 deletions
|
@ -13,6 +13,8 @@ class EmailAddressVerification < ApplicationRecord
|
|||
where.not(verified_at: nil).where(success: false)
|
||||
}
|
||||
|
||||
scope :by_domain, ->(domain_name) { where(domain: domain_name) }
|
||||
|
||||
def recently_verified?
|
||||
verified_at.present? &&
|
||||
verified_at > verification_period
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
namespace :verify_email do
|
||||
desc 'Stars verifying email jobs'
|
||||
desc 'Stars verifying email jobs for all the domain'
|
||||
task all_domains: :environment do
|
||||
verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain)
|
||||
verifications_by_domain.each do |_domain, verifications|
|
||||
|
@ -8,4 +8,16 @@ namespace :verify_email do
|
|||
next
|
||||
end
|
||||
end
|
||||
|
||||
# Need to be run like 'bundle exec rake verify_email:domain['gmail.com']'
|
||||
# In zsh syntax will be 'bundle exec rake verify_email:domain\['gmail.com'\]'
|
||||
# Default 'bundle exec rake verify_email:domain' wil use 'internet.ee' domain
|
||||
desc 'Stars verifying email jobs for domain stated in argument'
|
||||
task :domain, [:domain_name] => [:environment] do |_task, args|
|
||||
args.with_defaults(domain_name: "internet.ee")
|
||||
|
||||
verifications_by_domain = EmailAddressVerification.not_verified_recently
|
||||
.by_domain(args[:domain_name])
|
||||
verifications_by_domain.map{ |ver| VerifyEmailsJob.enqueue(ver.id) }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,7 +43,21 @@ class VerifyEmailTaskTest < ActiveSupport::TestCase
|
|||
assert @invalid_contact_verification.failed?
|
||||
end
|
||||
|
||||
def test_domain_task_verifies_for_one_domain
|
||||
capture_io { run_single_domain_task(@contact_verification.domain) }
|
||||
|
||||
@contact_verification.reload
|
||||
@invalid_contact_verification.reload
|
||||
|
||||
assert @contact_verification.verified?
|
||||
assert @invalid_contact_verification.not_verified?
|
||||
end
|
||||
|
||||
def run_task
|
||||
Rake::Task['verify_email:all_domains'].execute
|
||||
end
|
||||
|
||||
def run_single_domain_task(domain)
|
||||
Rake::Task["verify_email:domain"].invoke(domain)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue