diff --git a/app/interactions/domains/expired_pendings/process_clean.rb b/app/interactions/domains/expired_pendings/process_clean.rb index 63a8f1ba5..0fe5a7b37 100644 --- a/app/interactions/domains/expired_pendings/process_clean.rb +++ b/app/interactions/domains/expired_pendings/process_clean.rb @@ -9,7 +9,7 @@ module Domains clean_pendings to_stdout("DomainCron.clean_expired_pendings: ##{domain.id} (#{domain.name})") - UpdateWhoisRecordJob.enqueue domain.name, 'domain' + UpdateWhoisRecordJob.perform_later domain.name, 'domain' end private diff --git a/app/interactions/domains/update_confirm/process_update_confirmed.rb b/app/interactions/domains/update_confirm/process_update_confirmed.rb index 291253651..9530a0a6a 100644 --- a/app/interactions/domains/update_confirm/process_update_confirmed.rb +++ b/app/interactions/domains/update_confirm/process_update_confirmed.rb @@ -17,7 +17,7 @@ module Domains update_domain clean_pendings! - WhoisRecord.find_by(domain_id: domain.id).save # need to reload model + WhoisRecord.find_by(domain_id: domain.id)&.save # need to reload model end def update_domain diff --git a/app/jobs/application_job.rb b/app/jobs/application_job.rb index a009ace51..8e51414e9 100644 --- a/app/jobs/application_job.rb +++ b/app/jobs/application_job.rb @@ -1,2 +1,4 @@ class ApplicationJob < ActiveJob::Base + discard_on NoMethodError + queue_as :default end diff --git a/app/jobs/directo_invoice_forward_job.rb b/app/jobs/directo_invoice_forward_job.rb index 4b2c06e2c..e52caac20 100644 --- a/app/jobs/directo_invoice_forward_job.rb +++ b/app/jobs/directo_invoice_forward_job.rb @@ -1,5 +1,5 @@ -class DirectoInvoiceForwardJob < Que::Job - def run(monthly: false, dry: false) +class DirectoInvoiceForwardJob < ApplicationJob + def perform(monthly: false, dry: false) @dry = dry (@month = Time.zone.now - 1.month) if monthly diff --git a/app/jobs/dispute_status_update_job.rb b/app/jobs/dispute_status_update_job.rb index 547d56868..a1596aecb 100644 --- a/app/jobs/dispute_status_update_job.rb +++ b/app/jobs/dispute_status_update_job.rb @@ -1,5 +1,5 @@ -class DisputeStatusUpdateJob < Que::Job - def run(logger: Logger.new(STDOUT)) +class DisputeStatusUpdateJob < ApplicationJob + def perform(logger: Logger.new(STDOUT)) @logger = logger @backlog = { 'activated': 0, 'closed': 0, 'activate_fail': [], 'close_fail': [] } diff --git a/app/jobs/domain_delete_confirm_job.rb b/app/jobs/domain_delete_confirm_job.rb index afea3da59..88cd405ff 100644 --- a/app/jobs/domain_delete_confirm_job.rb +++ b/app/jobs/domain_delete_confirm_job.rb @@ -1,6 +1,4 @@ class DomainDeleteConfirmJob < ApplicationJob - queue_as :default - def perform(domain_id, action, initiator = nil) domain = Epp::Domain.find(domain_id) @@ -8,4 +6,34 @@ class DomainDeleteConfirmJob < ApplicationJob action: action, initiator: initiator) end + + private + + def action_confirmed(domain) + domain.notify_registrar(:poll_pending_delete_confirmed_by_registrant) + domain.apply_pending_delete! + raise_errors!(domain) + end + + def action_rejected(domain) + domain.statuses.delete(DomainStatus::PENDING_DELETE_CONFIRMATION) + domain.notify_registrar(:poll_pending_delete_rejected_by_registrant) + + domain.cancel_pending_delete + domain.save(validate: false) + raise_errors!(domain) + notify_on_domain(domain) + end + + def notify_on_domain(domain) + if domain.registrant_verification_token.blank? + Rails.logger.warn 'EMAIL NOT DELIVERED: registrant_verification_token is missing for '\ + "#{domain.name}" + elsif domain.registrant_verification_asked_at.blank? + Rails.logger.warn 'EMAIL NOT DELIVERED: registrant_verification_asked_at is missing for '\ + "#{domain.name}" + else + DomainDeleteMailer.rejected(domain).deliver_now + end + end end diff --git a/app/jobs/domain_delete_job.rb b/app/jobs/domain_delete_job.rb index 5577908c6..18061496f 100644 --- a/app/jobs/domain_delete_job.rb +++ b/app/jobs/domain_delete_job.rb @@ -1,6 +1,5 @@ -class DomainDeleteJob < Que::Job - - def run(domain_id) +class DomainDeleteJob < ApplicationJob + def perform(domain_id) domain = Domain.find(domain_id) Domains::Delete::DoDelete.run(domain: domain) diff --git a/app/jobs/domain_expire_email_job.rb b/app/jobs/domain_expire_email_job.rb index 286fe29ab..1ae6ce6e1 100644 --- a/app/jobs/domain_expire_email_job.rb +++ b/app/jobs/domain_expire_email_job.rb @@ -1,5 +1,5 @@ class DomainExpireEmailJob < Que::Job - def run(domain_id, email) + def perform(domain_id, email) domain = Domain.find(domain_id) return if domain.registered? diff --git a/app/jobs/domain_update_confirm_job.rb b/app/jobs/domain_update_confirm_job.rb index 403318ca6..b5085520e 100644 --- a/app/jobs/domain_update_confirm_job.rb +++ b/app/jobs/domain_update_confirm_job.rb @@ -1,6 +1,4 @@ class DomainUpdateConfirmJob < ApplicationJob - queue_as :default - def perform(domain_id, action, initiator = nil) domain = Epp::Domain.find(domain_id) Domains::UpdateConfirm::ProcessAction.run(domain: domain, diff --git a/app/jobs/regenerate_registrar_whoises_job.rb b/app/jobs/regenerate_registrar_whoises_job.rb index c5db82378..100a1cd87 100644 --- a/app/jobs/regenerate_registrar_whoises_job.rb +++ b/app/jobs/regenerate_registrar_whoises_job.rb @@ -1,10 +1,12 @@ -class RegenerateRegistrarWhoisesJob < Que::Job - def run(registrar_id) +class RegenerateRegistrarWhoisesJob < ApplicationJob + retry_on StandardError, wait: 2.seconds, attempts: 3 + + def perform(registrar_id) # no return as we want restart job if fails registrar = Registrar.find(registrar_id) registrar.whois_records.select(:name).find_in_batches(batch_size: 20) do |group| - UpdateWhoisRecordJob.enqueue group.map(&:name), 'domain' + UpdateWhoisRecordJob.perform_later group.map(&:name), 'domain' end end -end \ No newline at end of file +end diff --git a/app/jobs/regenerate_subzone_whoises_job.rb b/app/jobs/regenerate_subzone_whoises_job.rb index 280fa4088..ea8af8a18 100644 --- a/app/jobs/regenerate_subzone_whoises_job.rb +++ b/app/jobs/regenerate_subzone_whoises_job.rb @@ -1,11 +1,11 @@ -class RegenerateSubzoneWhoisesJob < Que::Job - def run +class RegenerateSubzoneWhoisesJob < ApplicationJob + def perform subzones = DNS::Zone.all subzones.each do |zone| next unless zone.subzone? - UpdateWhoisRecordJob.enqueue zone.origin, 'zone' + UpdateWhoisRecordJob.perform_later zone.origin, 'zone' end end end diff --git a/app/jobs/registrant_change_confirm_email_job.rb b/app/jobs/registrant_change_confirm_email_job.rb index 2883c10a6..09cf0caa4 100644 --- a/app/jobs/registrant_change_confirm_email_job.rb +++ b/app/jobs/registrant_change_confirm_email_job.rb @@ -1,5 +1,5 @@ -class RegistrantChangeConfirmEmailJob < Que::Job - def run(domain_id, new_registrant_id) +class RegistrantChangeConfirmEmailJob < ApplicationJob + def perform(domain_id, new_registrant_id) domain = Domain.find(domain_id) new_registrant = Registrant.find(new_registrant_id) diff --git a/app/jobs/registrant_change_expired_email_job.rb b/app/jobs/registrant_change_expired_email_job.rb new file mode 100644 index 000000000..68712af40 --- /dev/null +++ b/app/jobs/registrant_change_expired_email_job.rb @@ -0,0 +1,22 @@ +class RegistrantChangeExpiredEmailJob < ApplicationJob + def perform(domain_id) + domain = Domain.find(domain_id) + log(domain) + RegistrantChangeMailer.expired(domain: domain, + registrar: domain.registrar, + registrant: domain.registrant, + send_to: [domain.new_registrant_email, + domain.registrant.email]).deliver_now + end + + private + + def log(domain) + message = "Send RegistrantChangeMailer#expired email for domain #{domain.name} (##{domain.id}) to #{domain.new_registrant_email}" + logger.info(message) + end + + def logger + Rails.logger + end +end diff --git a/app/jobs/registrant_change_notice_email_job.rb b/app/jobs/registrant_change_notice_email_job.rb index cabd1db7f..cb0da5d06 100644 --- a/app/jobs/registrant_change_notice_email_job.rb +++ b/app/jobs/registrant_change_notice_email_job.rb @@ -1,5 +1,5 @@ -class RegistrantChangeNoticeEmailJob < Que::Job - def run(domain_id, new_registrant_id) +class RegistrantChangeNoticeEmailJob < ApplicationJob + def perform(domain_id, new_registrant_id) domain = Domain.find(domain_id) new_registrant = Registrant.find(new_registrant_id) log(domain, new_registrant) diff --git a/app/jobs/send_e_invoice_job.rb b/app/jobs/send_e_invoice_job.rb index e3880963e..f8b1f8296 100644 --- a/app/jobs/send_e_invoice_job.rb +++ b/app/jobs/send_e_invoice_job.rb @@ -1,13 +1,11 @@ -class SendEInvoiceJob < Que::Job - def run(invoice_id, payable = true) - invoice = run_condition(Invoice.find_by(id: invoice_id), payable: payable) +class SendEInvoiceJob < ApplicationJob + discard_on HTTPClient::TimeoutError - invoice.to_e_invoice(payable: payable).deliver - ActiveRecord::Base.transaction do - invoice.update(e_invoice_sent_at: Time.zone.now) - log_success(invoice) - destroy - end + def perform(invoice_id, payable = true) + invoice = Invoice.find_by(id: invoice_id) + return unless need_to_process_invoice?(invoice: invoice, payable: payable) + + process(invoice: invoice, payable: payable) rescue StandardError => e log_error(invoice: invoice, error: e) raise e @@ -15,10 +13,17 @@ class SendEInvoiceJob < Que::Job private - def run_condition(invoice, payable: true) - destroy unless invoice - destroy if invoice.do_not_send_e_invoice? && payable - invoice + def need_to_process_invoice?(invoice:, payable:) + return false if invoice.blank? + return false if invoice.do_not_send_e_invoice? && payable + + true + end + + def process(invoice:, payable:) + invoice.to_e_invoice(payable: payable).deliver + invoice.update(e_invoice_sent_at: Time.zone.now) + log_success(invoice) end def log_success(invoice) diff --git a/app/jobs/update_whois_record_job.rb b/app/jobs/update_whois_record_job.rb index d067807a0..1c90b8969 100644 --- a/app/jobs/update_whois_record_job.rb +++ b/app/jobs/update_whois_record_job.rb @@ -1,5 +1,5 @@ -class UpdateWhoisRecordJob < Que::Job - def run(names, type) +class UpdateWhoisRecordJob < ApplicationJob + def perform(names, type) Whois::Update.run(names: [names].flatten, type: type) end end diff --git a/app/jobs/verify_emails_job.rb b/app/jobs/verify_emails_job.rb index 75f4b7d91..0d3ec2078 100644 --- a/app/jobs/verify_emails_job.rb +++ b/app/jobs/verify_emails_job.rb @@ -1,14 +1,11 @@ -class VerifyEmailsJob < Que::Job - def run(verification_id) - email_address_verification = run_condition(EmailAddressVerification.find(verification_id)) +class VerifyEmailsJob < ApplicationJob + discard_on StandardError - return if email_address_verification.recently_verified? + def perform(verification_id) + email_address_verification = EmailAddressVerification.find(verification_id) + return unless need_to_verify?(email_address_verification) - ActiveRecord::Base.transaction do - email_address_verification.verify - log_success(email_address_verification) - destroy - end + process(email_address_verification) rescue StandardError => e log_error(verification: email_address_verification, error: e) raise e @@ -16,11 +13,16 @@ class VerifyEmailsJob < Que::Job private - def run_condition(email_address_verification) - destroy unless email_address_verification - destroy if email_address_verification.recently_verified? + def need_to_verify?(email_address_verification) + return false if email_address_verification.blank? + return false if email_address_verification.recently_verified? - email_address_verification + true + end + + def process(email_address_verification) + email_address_verification.verify + log_success(email_address_verification) end def logger diff --git a/app/models/blocked_domain.rb b/app/models/blocked_domain.rb index d292827dc..f4e18bffc 100644 --- a/app/models/blocked_domain.rb +++ b/app/models/blocked_domain.rb @@ -34,6 +34,6 @@ class BlockedDomain < ApplicationRecord end def remove_data - UpdateWhoisRecordJob.enqueue name, 'blocked' + UpdateWhoisRecordJob.perform_later name, 'blocked' end end diff --git a/app/models/concerns/domain/deletable.rb b/app/models/concerns/domain/deletable.rb index 50c418feb..db81856b8 100644 --- a/app/models/concerns/domain/deletable.rb +++ b/app/models/concerns/domain/deletable.rb @@ -7,11 +7,14 @@ module Domain::Deletable DomainStatus::FORCE_DELETE, ].freeze + def deletion_time + @deletion_time ||= Time.zone.at(rand(deletion_time_span)) + end + private def delete_later - deletion_time = Time.zone.at(rand(deletion_time_span)) - DomainDeleteJob.enqueue(id, run_at: deletion_time, priority: 1) + DomainDeleteJob.set(wait_until: deletion_time).perform_later(id) logger.info "Domain #{name} is scheduled to be deleted around #{deletion_time}" end diff --git a/app/models/concerns/invoice/payable.rb b/app/models/concerns/invoice/payable.rb index ad91b886e..6e2cc19b4 100644 --- a/app/models/concerns/invoice/payable.rb +++ b/app/models/concerns/invoice/payable.rb @@ -11,7 +11,7 @@ module Invoice::Payable end def paid? - account_activity + account_activity.present? end def receipt_date diff --git a/app/models/concerns/zone/whois_queryable.rb b/app/models/concerns/zone/whois_queryable.rb index e4a6c1314..7c6ff511d 100644 --- a/app/models/concerns/zone/whois_queryable.rb +++ b/app/models/concerns/zone/whois_queryable.rb @@ -11,7 +11,7 @@ module Zone::WhoisQueryable end def update_whois_record - UpdateWhoisRecordJob.enqueue origin, 'zone' + UpdateWhoisRecordJob.perform_later origin, 'zone' end def generate_data diff --git a/app/models/contact.rb b/app/models/contact.rb index 61d49c10c..c6e3e22ba 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -492,7 +492,7 @@ class Contact < ApplicationRecord return if saved_changes.slice(*(self.class.column_names - ignored_columns)).empty? names = related_domain_descriptions.keys - UpdateWhoisRecordJob.enqueue(names, 'domain') if names.present? + UpdateWhoisRecordJob.perform_later(names, 'domain') if names.present? end def children_log diff --git a/app/models/dispute.rb b/app/models/dispute.rb index 45ff27274..6690e0e3c 100644 --- a/app/models/dispute.rb +++ b/app/models/dispute.rb @@ -84,7 +84,7 @@ class Dispute < ApplicationRecord end def remove_data - UpdateWhoisRecordJob.enqueue domain_name, 'disputed' + UpdateWhoisRecordJob.perform_later domain_name, 'disputed' end def fill_empty_passwords diff --git a/app/models/domain.rb b/app/models/domain.rb index 04491bc53..68820060f 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -425,8 +425,8 @@ class Domain < ApplicationRecord new_registrant_email = registrant.email new_registrant_name = registrant.name - RegistrantChangeConfirmEmailJob.enqueue(id, new_registrant_id) - RegistrantChangeNoticeEmailJob.enqueue(id, new_registrant_id) + RegistrantChangeConfirmEmailJob.perform_later(id, new_registrant_id) + RegistrantChangeNoticeEmailJob.perform_later(id, new_registrant_id) reload @@ -670,7 +670,7 @@ class Domain < ApplicationRecord end def update_whois_record - UpdateWhoisRecordJob.enqueue name, 'domain' + UpdateWhoisRecordJob.perform_later name, 'domain' end def status_notes_array=(notes) diff --git a/app/models/registrant_verification.rb b/app/models/registrant_verification.rb index 4e8e6afe9..b689d9c1c 100644 --- a/app/models/registrant_verification.rb +++ b/app/models/registrant_verification.rb @@ -30,12 +30,12 @@ class RegistrantVerification < ApplicationRecord def domain_registrant_delete_confirm!(initiator) self.action_type = DOMAIN_DELETE self.action = CONFIRMED - DomainDeleteConfirmJob.perform_later domain.id, CONFIRMED, initiator if save + DomainDeleteConfirmJob.perform_later(domain.id, CONFIRMED, initiator) if save end def domain_registrant_delete_reject!(initiator) self.action_type = DOMAIN_DELETE self.action = REJECTED - DomainDeleteConfirmJob.perform_later domain.id, REJECTED, initiator if save + DomainDeleteConfirmJob.perform_later(domain.id, REJECTED, initiator) if save end end diff --git a/app/models/registrar.rb b/app/models/registrar.rb index 335fb9115..264029c8a 100644 --- a/app/models/registrar.rb +++ b/app/models/registrar.rb @@ -43,7 +43,7 @@ class Registrar < ApplicationRecord after_commit :update_whois_records def update_whois_records return true unless changed? && (changes.keys & WHOIS_TRIGGERS).present? - RegenerateRegistrarWhoisesJob.enqueue id + RegenerateRegistrarWhoisesJob.perform_later id end self.ignored_columns = %w[legacy_id] @@ -104,7 +104,7 @@ class Registrar < ApplicationRecord InvoiceMailer.invoice_email(invoice: invoice, recipient: billing_email).deliver_now end - SendEInvoiceJob.enqueue(invoice.id, payable) + SendEInvoiceJob.perform_later(invoice.id, payable) invoice end diff --git a/app/models/reserved_domain.rb b/app/models/reserved_domain.rb index 4c9df3269..a45d06e83 100644 --- a/app/models/reserved_domain.rb +++ b/app/models/reserved_domain.rb @@ -59,6 +59,6 @@ class ReservedDomain < ApplicationRecord alias_method :update_whois_record, :generate_data def remove_data - UpdateWhoisRecordJob.enqueue name, 'reserved' + UpdateWhoisRecordJob.perform_later name, 'reserved' end end diff --git a/config/application.rb b/config/application.rb index 0ab5aa8bb..4455a8a77 100644 --- a/config/application.rb +++ b/config/application.rb @@ -44,6 +44,8 @@ module DomainNameRegistry config.active_record.schema_format = :sql + config.active_job.queue_adapter = :que + config.generators do |g| g.stylesheets false g.javascripts false diff --git a/config/environments/production.rb b/config/environments/production.rb index e1966d6ba..0636788c5 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -56,7 +56,7 @@ Rails.application.configure do # config.cache_store = :mem_cache_store # Use a real queuing backend for Active Job (and separate queues per environment) - # config.active_job.queue_adapter = :resque + config.active_job.queue_adapter = :que # config.active_job.queue_name_prefix = "domain_name_registry_#{Rails.env}" config.action_mailer.perform_caching = false diff --git a/config/environments/test.rb b/config/environments/test.rb index c55e59e31..d10de6d19 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -14,6 +14,8 @@ Rails.application.configure do # preloads Rails for running tests, you may have to set it to true. config.eager_load = false + config.active_job.queue_adapter = :test + config.consider_all_requests_local = true config.action_controller.perform_caching = false diff --git a/lib/tasks/verify_email.rake b/lib/tasks/verify_email.rake index d49bb38b9..daffabf19 100644 --- a/lib/tasks/verify_email.rake +++ b/lib/tasks/verify_email.rake @@ -4,7 +4,7 @@ namespace :verify_email do verifications_by_domain = EmailAddressVerification.not_verified_recently.group_by(&:domain) verifications_by_domain.each do |_domain, verifications| ver = verifications.sample # Verify random email to not to clog the SMTP servers - VerifyEmailsJob.enqueue(ver.id) + VerifyEmailsJob.perform_later(ver.id) next end end @@ -18,6 +18,6 @@ namespace :verify_email do verifications_by_domain = EmailAddressVerification.not_verified_recently .by_domain(args[:domain_name]) - verifications_by_domain.map { |ver| VerifyEmailsJob.enqueue(ver.id) } + verifications_by_domain.map { |ver| VerifyEmailsJob.perform_later(ver.id) } end end diff --git a/lib/tasks/whois.rake b/lib/tasks/whois.rake index 52be7e17f..57b054d95 100644 --- a/lib/tasks/whois.rake +++ b/lib/tasks/whois.rake @@ -23,22 +23,23 @@ namespace :whois do print "\n-----> Update domains whois_records" Domain.find_in_batches.each do |group| - UpdateWhoisRecordJob.enqueue group.map(&:name), 'domain' + UpdateWhoisRecordJob.perform_later group.map(&:name), 'domain' end print "\n-----> Update blocked domains whois_records" BlockedDomain.find_in_batches.each do |group| - UpdateWhoisRecordJob.enqueue group.map(&:name), 'blocked' + UpdateWhoisRecordJob.perform_later group.map(&:name), 'blocked' end print "\n-----> Update reserved domains whois_records" ReservedDomain.find_in_batches.each do |group| - UpdateWhoisRecordJob.enqueue group.map(&:name), 'reserved' + UpdateWhoisRecordJob.perform_later group.map(&:name), 'reserved' end print "\n-----> Update disputed domains whois_records" Dispute.active.find_in_batches.each do |group| - UpdateWhoisRecordJob.enqueue group.map(&:domain_name), 'disputed' + + UpdateWhoisRecordJob.perform_later group.map(&:domain_name), 'disputed' end end puts "\n-----> all done in #{(Time.zone.now.to_f - start).round(2)} seconds" diff --git a/test/integration/epp/domain/delete/base_test.rb b/test/integration/epp/domain/delete/base_test.rb index d32a89f63..830d7363d 100644 --- a/test/integration/epp/domain/delete/base_test.rb +++ b/test/integration/epp/domain/delete/base_test.rb @@ -92,12 +92,13 @@ class EppDomainDeleteBaseTest < EppTestCase perform_enqueued_jobs do post epp_delete_path, params: { frame: request_xml }, headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } end + @domain.reload assert @domain.registrant_verification_asked? assert @domain.pending_delete_confirmation? - assert_emails 1 assert_epp_response :completed_successfully_action_pending + assert_emails 1 end def test_skips_registrant_confirmation_when_not_required diff --git a/test/integration/epp/domain/update/base_test.rb b/test/integration/epp/domain/update/base_test.rb index 83ba65478..cf3ee7fe9 100644 --- a/test/integration/epp/domain/update/base_test.rb +++ b/test/integration/epp/domain/update/base_test.rb @@ -2,6 +2,7 @@ require 'test_helper' class EppDomainUpdateBaseTest < EppTestCase include ActionMailer::TestHelper + include ActiveJob::TestHelper setup do @domain = domains(:shop) @@ -134,15 +135,17 @@ class EppDomainUpdateBaseTest < EppTestCase XML - post epp_update_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_no_enqueued_jobs + assert_enqueued_jobs 3 do + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end @domain.reload assert_epp_response :completed_successfully_action_pending assert_not_equal new_registrant, @domain.registrant assert @domain.registrant_verification_asked? assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE - assert_verification_and_notification_emails end def test_domain_should_doesnt_have_pending_update_when_updated_registrant_with_same_idents_data @@ -211,15 +214,17 @@ class EppDomainUpdateBaseTest < EppTestCase XML - post epp_update_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_no_enqueued_jobs + assert_enqueued_jobs 3 do + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end @domain.reload assert_epp_response :completed_successfully_action_pending assert_not_equal new_registrant, @domain.registrant assert @domain.registrant_verification_asked? assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE - assert_verification_and_notification_emails end def test_updates_registrant_when_legaldoc_is_not_mandatory @@ -247,15 +252,17 @@ class EppDomainUpdateBaseTest < EppTestCase XML - post epp_update_path, params: { frame: request_xml }, - headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + assert_no_enqueued_jobs + assert_enqueued_jobs 3 do + post epp_update_path, params: { frame: request_xml }, + headers: { 'HTTP_COOKIE' => 'session=api_bestnames' } + end @domain.reload assert_epp_response :completed_successfully_action_pending assert_not_equal new_registrant, @domain.registrant assert @domain.registrant_verification_asked? assert_includes @domain.statuses, DomainStatus::PENDING_UPDATE - assert_verification_and_notification_emails end def test_dows_not_update_registrant_when_legaldoc_is_mandatory diff --git a/test/jobs/active_job_queuing_test.rb b/test/jobs/active_job_queuing_test.rb new file mode 100644 index 000000000..9f60a5b06 --- /dev/null +++ b/test/jobs/active_job_queuing_test.rb @@ -0,0 +1,45 @@ +$VERBOSE=nil +require 'test_helper' + +class ActiveJobQueuingTest < ActiveJob::TestCase + + def test_job_discarded_after_error + assert_no_enqueued_jobs + assert_performed_jobs 1 do + TestDiscardedJob.perform_later + end + assert_no_enqueued_jobs + end + + def test_job_retried_after_error + assert_no_enqueued_jobs + assert_raises StandardError do + assert_performed_jobs 3 do + TestRetriedJob.perform_later + end + end + + assert_no_enqueued_jobs + end + +end + +class TestDiscardedJob < ApplicationJob + queue_as :default + + discard_on StandardError + + def perform + raise StandardError + end +end + +class TestRetriedJob < ApplicationJob + queue_as :default + + retry_on StandardError, wait: 2.seconds, attempts: 3 + + def perform + raise StandardError + end +end diff --git a/test/jobs/directo_invoice_forward_job_test.rb b/test/jobs/directo_invoice_forward_job_test.rb index 4e0edf7e5..4a4fcf86d 100644 --- a/test/jobs/directo_invoice_forward_job_test.rb +++ b/test/jobs/directo_invoice_forward_job_test.rb @@ -38,7 +38,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase end.to_return(status: 200, body: response) assert_nothing_raised do - DirectoInvoiceForwardJob.run(monthly: false, dry: false) + DirectoInvoiceForwardJob.perform_now(monthly: false, dry: false) end assert_not_empty @invoice.directo_records.first.request @@ -52,7 +52,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase Setting.directo_monthly_number_max = 30991 assert_raises 'RuntimeError' do - DirectoInvoiceForwardJob.run(monthly: true, dry: false) + DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false) end end @@ -78,7 +78,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase end.to_return(status: 200, body: response) assert_difference 'Setting.directo_monthly_number_last' do - DirectoInvoiceForwardJob.run(monthly: true, dry: false) + DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false) end end @@ -103,7 +103,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase end.to_return(status: 200, body: response) assert_difference 'Setting.directo_monthly_number_last' do - DirectoInvoiceForwardJob.run(monthly: true, dry: false) + DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false) end end @@ -126,7 +126,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase end.to_return(status: 200, body: response) assert_difference 'Setting.directo_monthly_number_last' do - DirectoInvoiceForwardJob.run(monthly: true, dry: false) + DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false) end end @@ -148,7 +148,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase end.to_return(status: 200, body: response) assert_difference 'Setting.directo_monthly_number_last' do - DirectoInvoiceForwardJob.run(monthly: true, dry: false) + DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false) end end @@ -186,7 +186,7 @@ class DirectoInvoiceForwardJobTest < ActiveSupport::TestCase (body.include? 'StartDate') && (body.include? 'EndDate') && (body.include? 'goodnames') end.to_return(status: 200, body: response) - DirectoInvoiceForwardJob.run(monthly: true, dry: false) + DirectoInvoiceForwardJob.perform_now(monthly: true, dry: false) assert_requested first_registrar_stub assert_requested second_registrar_stub diff --git a/test/jobs/dispute_status_update_job_test.rb b/test/jobs/dispute_status_update_job_test.rb index e70e58c04..7784cdeac 100644 --- a/test/jobs/dispute_status_update_job_test.rb +++ b/test/jobs/dispute_status_update_job_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class DisputeStatusUpdateJobTest < ActiveSupport::TestCase +class DisputeStatusUpdateJobTest < ActiveJob::TestCase setup do travel_to Time.zone.parse('2010-10-05') @logger = Rails.logger @@ -8,13 +8,13 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase def test_nothing_is_raised assert_nothing_raised do - DisputeStatusUpdateJob.run(logger: @logger) + DisputeStatusUpdateJob.perform_now(logger: @logger) end end def test_whois_data_added_when_dispute_activated dispute = disputes(:future) - DisputeStatusUpdateJob.run(logger: @logger) + DisputeStatusUpdateJob.perform_now(logger: @logger) whois_record = Whois::Record.find_by(name: dispute.domain_name) assert whois_record.present? @@ -25,7 +25,7 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase dispute = disputes(:active) dispute.update!(starts_at: Time.zone.today - 3.years - 1.day) - DisputeStatusUpdateJob.run(logger: @logger) + DisputeStatusUpdateJob.perform_now(logger: @logger) dispute.reload assert dispute.closed @@ -37,7 +37,9 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase def test_registered_domain_whois_data_is_added Dispute.create(domain_name: 'shop.test', starts_at: '2010-07-05') travel_to Time.zone.parse('2010-07-05') - DisputeStatusUpdateJob.run(logger: @logger) + perform_enqueued_jobs do + DisputeStatusUpdateJob.perform_now(logger: @logger) + end whois_record = Whois::Record.find_by(name: 'shop.test') assert_includes whois_record.json['status'], 'disputed' @@ -53,7 +55,9 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase force_delete_date: nil) # Dispute status is added automatically if starts_at is not in future - Dispute.create(domain_name: 'shop.test', starts_at: Time.zone.parse('2010-07-05')) + perform_enqueued_jobs do + Dispute.create(domain_name: 'shop.test', starts_at: Time.zone.parse('2010-07-05')) + end domain.reload whois_record = Whois::Record.find_by(name: 'shop.test') @@ -62,7 +66,9 @@ class DisputeStatusUpdateJobTest < ActiveSupport::TestCase # Dispute status is removed night time day after it's ended travel_to Time.zone.parse('2010-07-05') + 3.years + 1.day - DisputeStatusUpdateJob.run(logger: @logger) + perform_enqueued_jobs do + DisputeStatusUpdateJob.perform_now(logger: @logger) + end whois_record.reload assert_not whois_record.json['status'].include? 'disputed' diff --git a/test/jobs/regenerate_subzone_whoises_job_test.rb b/test/jobs/regenerate_subzone_whoises_job_test.rb index 6c29e4be7..b6b6e97fe 100644 --- a/test/jobs/regenerate_subzone_whoises_job_test.rb +++ b/test/jobs/regenerate_subzone_whoises_job_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegenerateSubzoneWhoisesJobTest < ActiveSupport::TestCase +class RegenerateSubzoneWhoisesJobTest < ActiveJob::TestCase def test_regenerates_whois_data_only_for_subzones subzone = dns_zones(:one).dup subzone.origin = 'subzone.test' @@ -11,7 +11,9 @@ class RegenerateSubzoneWhoisesJobTest < ActiveSupport::TestCase assert_nil Whois::Record.find_by(name: subzone.origin) assert_nil Whois::Record.find_by(name: dns_zones(:one).origin) - RegenerateSubzoneWhoisesJob.run + perform_enqueued_jobs do + RegenerateSubzoneWhoisesJob.perform_now + end record = Whois::Record.find_by(name: subzone.origin) assert record assert record.json['dnssec_keys'].is_a?(Array) diff --git a/test/jobs/registrant_change_confirm_email_job_test.rb b/test/jobs/registrant_change_confirm_email_job_test.rb index 0e38fb9a4..5341a59b2 100644 --- a/test/jobs/registrant_change_confirm_email_job_test.rb +++ b/test/jobs/registrant_change_confirm_email_job_test.rb @@ -11,8 +11,8 @@ class RegistrantChangeConfirmEmailJobTest < ActiveSupport::TestCase domain_id = domains(:shop).id new_registrant_id = contacts(:william).id - RegistrantChangeConfirmEmailJob.enqueue(domain_id, new_registrant_id) + RegistrantChangeConfirmEmailJob.perform_now(domain_id, new_registrant_id) assert_emails 1 end -end \ No newline at end of file +end diff --git a/test/jobs/registrant_change_expired_email_job_test.rb b/test/jobs/registrant_change_expired_email_job_test.rb new file mode 100644 index 000000000..f3c194b5f --- /dev/null +++ b/test/jobs/registrant_change_expired_email_job_test.rb @@ -0,0 +1,24 @@ +require 'test_helper' + +class RegistrantChangeExpiredEmailJobTest < ActiveJob::TestCase + include ActionMailer::TestHelper + + setup do + ActionMailer::Base.deliveries.clear + end + + def test_delivers_email + domain = domains(:shop) + domain.update!(pending_json: {new_registrant_email: 'aaa@bbb.com'}) + domain_id = domain.id + + assert_performed_jobs 1 do + perform_enqueued_jobs do + RegistrantChangeExpiredEmailJob.perform_later(domain_id) + end + end + + assert_emails 1 + end + +end diff --git a/test/jobs/registrant_change_notice_email_job_test.rb b/test/jobs/registrant_change_notice_email_job_test.rb index 8213ea3b9..df6bcc6e5 100644 --- a/test/jobs/registrant_change_notice_email_job_test.rb +++ b/test/jobs/registrant_change_notice_email_job_test.rb @@ -11,8 +11,8 @@ class RegistrantChangeNoticeEmailJobTest < ActiveSupport::TestCase domain_id = domains(:shop).id new_registrant_id = contacts(:william).id - RegistrantChangeNoticeEmailJob.enqueue(domain_id, new_registrant_id) + RegistrantChangeNoticeEmailJob.perform_now(domain_id, new_registrant_id) assert_emails 1 end -end \ No newline at end of file +end diff --git a/test/jobs/send_e_invoice_job_test.rb b/test/jobs/send_e_invoice_job_test.rb index 86d761b42..ca1e50eb7 100644 --- a/test/jobs/send_e_invoice_job_test.rb +++ b/test/jobs/send_e_invoice_job_test.rb @@ -1,43 +1,22 @@ require 'test_helper' -class SendEInvoiceJobTest < ActiveSupport::TestCase +class SendEInvoiceJobTest < ActiveJob::TestCase def teardown EInvoice.provider = EInvoice::Providers::TestProvider.new EInvoice::Providers::TestProvider.deliveries.clear end - def test_if_invoice_is_sended + def test_if_invoice_is_sent @invoice = invoices(:one) + @invoice.account_activity.destroy EInvoice.provider = EInvoice::Providers::TestProvider.new EInvoice::Providers::TestProvider.deliveries.clear assert_nothing_raised do - SendEInvoiceJob.enqueue(@invoice.id, true) - end - @invoice.reload - - assert_not @invoice.e_invoice_sent_at.blank? - assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count - end - - def test_if_invoice_sending_retries - @invoice = invoices(:one) - provider_config = { password: nil, - test_mode: true } - EInvoice.provider = EInvoice::Providers::OmnivaProvider.new(provider_config) - stub_request(:get, "https://testfinance.post.ee/finance/erp/erpServices.wsdl").to_timeout - - assert_raise HTTPClient::TimeoutError do - SendEInvoiceJob.enqueue(@invoice.id, true) - end - assert @invoicee_invoice_sent_at.blank? - - EInvoice.provider = EInvoice::Providers::TestProvider.new - EInvoice::Providers::TestProvider.deliveries.clear - - assert_nothing_raised do - SendEInvoiceJob.enqueue(@invoice.id, true) + perform_enqueued_jobs do + SendEInvoiceJob.perform_now(@invoice.id, true) + end end @invoice.reload diff --git a/test/jobs/update_whois_record_job_test.rb b/test/jobs/update_whois_record_job_test.rb new file mode 100644 index 000000000..77bc7bb23 --- /dev/null +++ b/test/jobs/update_whois_record_job_test.rb @@ -0,0 +1,28 @@ +require 'test_helper' + +class SendEInvoiceJobTest < ActiveJob::TestCase + + def test_job_is_updating_domains + domain_names = Domain.find_in_batches.first.map(&:name) + assert_domains_processed_by_task(domain_names, 'domain') + end + + def test_job_is_updating_blocked_domains + domain_names = BlockedDomain.find_in_batches.first.map(&:name) + assert_domains_processed_by_task(domain_names, 'blocked') + end + + def test_job_is_updating_reserved_domains + domain_names = ReservedDomain.find_in_batches.first.map(&:name) + assert_domains_processed_by_task(domain_names, 'reserved') + end + + private + + def assert_domains_processed_by_task(domain_names, type) + Rake::Task['whois:regenerate'].execute + + perform_enqueued_jobs + assert_performed_with(job: UpdateWhoisRecordJob, args: [domain_names, type]) + end +end diff --git a/test/jobs/verify_emails_job_test.rb b/test/jobs/verify_emails_job_test.rb index f55a474db..49a08fe73 100644 --- a/test/jobs/verify_emails_job_test.rb +++ b/test/jobs/verify_emails_job_test.rb @@ -1,6 +1,6 @@ require "test_helper" -class VerifyEmailsJobTest < ActiveSupport::TestCase +class VerifyEmailsJobTest < ActiveJob::TestCase def setup @contact = contacts(:john) @invalid_contact = contacts(:invalid_email) @@ -33,7 +33,9 @@ class VerifyEmailsJobTest < ActiveSupport::TestCase end def test_job_checks_if_email_valid - VerifyEmailsJob.run(@contact_verification.id) + perform_enqueued_jobs do + VerifyEmailsJob.perform_now(@contact_verification.id) + end @contact_verification.reload assert @contact_verification.success @@ -44,14 +46,18 @@ class VerifyEmailsJobTest < ActiveSupport::TestCase @contact_verification.update(success: true, verified_at: old_verified_at) assert @contact_verification.recently_verified? - VerifyEmailsJob.run(@contact_verification.id) + perform_enqueued_jobs do + VerifyEmailsJob.perform_now(@contact_verification.id) + end @contact_verification.reload assert_in_delta @contact_verification.verified_at.to_i, old_verified_at.to_i, 1 end def test_job_checks_if_email_invalid - VerifyEmailsJob.run(@invalid_contact_verification.id) + perform_enqueued_jobs do + VerifyEmailsJob.perform_now(@invalid_contact_verification.id) + end @contact_verification.reload refute @contact_verification.success diff --git a/test/mailers/previews/registrant_change_mailer_preview.rb b/test/mailers/previews/registrant_change_mailer_preview.rb index ac3dab2a9..03b4b494e 100644 --- a/test/mailers/previews/registrant_change_mailer_preview.rb +++ b/test/mailers/previews/registrant_change_mailer_preview.rb @@ -37,6 +37,8 @@ class RegistrantChangeMailerPreview < ActionMailer::Preview def expired RegistrantChangeMailer.expired(domain: @domain, registrar: @domain.registrar, - registrant: @domain.registrant) + registrant: @domain.registrant, + send_to: [@domain.new_registrant_email, + @domain.registrant.email]) end end diff --git a/test/models/contact_test.rb b/test/models/contact_test.rb index e6dc2422f..3c0669890 100644 --- a/test/models/contact_test.rb +++ b/test/models/contact_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class ContactTest < ActiveSupport::TestCase +class ContactTest < ActiveJob::TestCase setup do @contact = contacts(:john) @old_validation_type = Truemail.configure.default_validation_type @@ -336,7 +336,9 @@ class ContactTest < ActiveSupport::TestCase @contact.name = 'SomeReallyWeirdRandomTestName' domain = @contact.registrant_domains.first - @contact.save! + perform_enqueued_jobs do + @contact.save! + end assert_equal domain.whois_record.try(:json).try(:[], 'registrant'), @contact.name end diff --git a/test/models/dns/zone_test.rb b/test/models/dns/zone_test.rb index fab4c6355..47b0503b5 100644 --- a/test/models/dns/zone_test.rb +++ b/test/models/dns/zone_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class DNS::ZoneTest < ActiveSupport::TestCase +class DNS::ZoneTest < ActiveJob::TestCase def test_valid_zone_fixture_is_valid assert valid_zone.valid?, proc { valid_zone.errors.full_messages } end @@ -134,7 +134,9 @@ class DNS::ZoneTest < ActiveSupport::TestCase subzone = dns_zones(:one).dup subzone.origin = 'sub.zone' - subzone.save + perform_enqueued_jobs do + subzone.save + end whois_record = Whois::Record.find_by(name: subzone.origin) assert whois_record.present? @@ -144,7 +146,9 @@ class DNS::ZoneTest < ActiveSupport::TestCase subzone = dns_zones(:one).dup subzone.origin = 'sub.zone' - subzone.save + perform_enqueued_jobs do + subzone.save + end whois_record = Whois::Record.find_by(name: subzone.origin) assert whois_record.present? @@ -170,11 +174,15 @@ class DNS::ZoneTest < ActiveSupport::TestCase subzone = dns_zones(:one).dup subzone.origin = 'sub.zone' - subzone.save + perform_enqueued_jobs do + subzone.save + end assert Whois::Record.find_by(name: subzone.origin).present? - subzone.destroy + perform_enqueued_jobs do + subzone.destroy + end assert_nil Whois::Record.find_by(name: subzone.origin) end diff --git a/test/models/domain/releasable/auctionable_test.rb b/test/models/domain/releasable/auctionable_test.rb index d24f46913..97d66be4f 100644 --- a/test/models/domain/releasable/auctionable_test.rb +++ b/test/models/domain/releasable/auctionable_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class DomainReleasableAuctionableTest < ActiveSupport::TestCase +class DomainReleasableAuctionableTest < ActiveJob::TestCase # Needed for `test_updates_whois` test because of `after_commit :update_whois_record` in Domain self.use_transactional_tests = false @@ -65,7 +65,9 @@ class DomainReleasableAuctionableTest < ActiveSupport::TestCase travel_to Time.zone.parse('2010-07-05') old_whois = @domain.whois_record - Domain.release_domains + perform_enqueued_jobs do + Domain.release_domains + end assert_raises ActiveRecord::RecordNotFound do old_whois.reload diff --git a/test/models/domain/releasable/discardable_test.rb b/test/models/domain/releasable/discardable_test.rb index d7c2a8ed2..796b4eac5 100644 --- a/test/models/domain/releasable/discardable_test.rb +++ b/test/models/domain/releasable/discardable_test.rb @@ -1,7 +1,10 @@ require 'test_helper' class DomainReleasableDiscardableTest < ActiveSupport::TestCase + include ActiveJob::TestHelper + setup do + ActiveJob::Base.queue_adapter = :test @domain = domains(:shop) end @@ -64,16 +67,18 @@ class DomainReleasableDiscardableTest < ActiveSupport::TestCase travel_to Time.zone.parse('2010-07-05') @domain.update_columns(delete_date: '2010-07-05') - Domain.release_domains + + assert_enqueued_with(job: DomainDeleteJob) do + Domain.release_domains + end other_domain = domains(:airport) other_domain.update_columns(delete_date: '2010-07-05') - Domain.release_domains + assert_enqueued_with(job: DomainDeleteJob) do + Domain.release_domains + end - background_job = QueJob.find_by("args->>0 = '#{@domain.id}'", job_class: DomainDeleteJob.name) - other_background_job = QueJob.find_by("args->>0 = '#{other_domain.id}'", - job_class: DomainDeleteJob.name) - assert_not_equal background_job.run_at, other_background_job.run_at + assert_not other_domain.deletion_time == @domain.deletion_time end def test_discarding_a_domain_bypasses_validation diff --git a/test/models/registrar_test.rb b/test/models/registrar_test.rb index 091b8e6f4..e7d53e075 100644 --- a/test/models/registrar_test.rb +++ b/test/models/registrar_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class RegistrarTest < ActiveSupport::TestCase +class RegistrarTest < ActiveJob::TestCase setup do @registrar = registrars(:bestnames) @original_default_language = Setting.default_language @@ -213,7 +213,9 @@ class RegistrarTest < ActiveSupport::TestCase def test_issues_e_invoice_along_with_invoice EInvoice::Providers::TestProvider.deliveries.clear - @registrar.issue_prepayment_invoice(100) + perform_enqueued_jobs do + @registrar.issue_prepayment_invoice(100) + end assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count end diff --git a/test/system/registrant_area/domains/domain_delete_confirms_test.rb b/test/system/registrant_area/domains/domain_delete_confirms_test.rb new file mode 100644 index 000000000..259120b18 --- /dev/null +++ b/test/system/registrant_area/domains/domain_delete_confirms_test.rb @@ -0,0 +1,42 @@ +require 'application_system_test_case' + +class DomainDeleteConfirmsTest < ApplicationSystemTestCase + include ActionMailer::TestHelper + setup do + @user = users(:registrant) + sign_in @user + + @domain = domains(:shop) + @domain.registrant_verification_asked!('\n', @user.id) + @domain.pending_delete! + end + + def test_enqueues_approve_job_after_verification + visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token) + + click_on 'Confirm domain delete' + + assert_text 'Domain registrant change has successfully received.' + + assert_enqueued_jobs 1, only: DomainDeleteConfirmJob + end + + def test_enqueues_reject_job_after_verification + visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token) + + click_on 'Reject domain delete' + + assert_text 'Domain registrant change has been rejected successfully.' + + assert_enqueued_jobs 1, only: DomainDeleteConfirmJob + end + + def test_saves_whodunnit_info_after_verifivation + visit registrant_domain_delete_confirm_url(@domain.id, token: @domain.registrant_verification_token) + token = @domain.registrant_verification_token + click_on 'Confirm domain delete' + assert_text 'Domain registrant change has successfully received.' + + refute RegistrantVerification.find_by(verification_token:token).updator_str.empty? + end +end diff --git a/test/tasks/emails/verify_email_task_test.rb b/test/tasks/emails/verify_email_task_test.rb index 7cca11845..fd4d3cf11 100644 --- a/test/tasks/emails/verify_email_task_test.rb +++ b/test/tasks/emails/verify_email_task_test.rb @@ -1,6 +1,6 @@ require 'test_helper' -class VerifyEmailTaskTest < ActiveSupport::TestCase +class VerifyEmailTaskTest < ActiveJob::TestCase def setup @contact = contacts(:john) @@ -54,10 +54,14 @@ class VerifyEmailTaskTest < ActiveSupport::TestCase end def run_task - Rake::Task['verify_email:all_domains'].execute + perform_enqueued_jobs do + Rake::Task['verify_email:all_domains'].execute + end end def run_single_domain_task(domain) - Rake::Task["verify_email:domain"].invoke(domain) + perform_enqueued_jobs do + Rake::Task["verify_email:domain"].invoke(domain) + end end end diff --git a/test/test_helper.rb b/test/test_helper.rb index fe20f7a6e..578c3ee9b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -27,6 +27,8 @@ require 'rake' Rake::Task.clear Rails.application.load_tasks +ActiveJob::Base.queue_adapter = :test + class CompanyRegisterClientStub Company = Struct.new(:registration_number, :company_name)