(очередь RoR delivery_later), как ожидается, поставит ровно 1 задание с [NotificationGroupMailer], но поставит в очередь 0 - PullRequest
0 голосов
/ 18 марта 2020

У меня есть следующий тестовый код Rspe c:

describe '.send_expiration_reminders' do
  before(:each) do
    @notification_group = create(:notification_group)
    @notification_group.notification_groups_contacts << create(:notification_groups_contact)
    @notification_group.scanned_certificates << create(:scanned_certificate, :expired_today)

    ['-15', '0', '15', '30', '60'].each do |reminder_value|
      create(:preference, owner_id: @notification_group.id, value: reminder_value)
    end
  end

  after do
    clear_enqueued_jobs
  end

  context 'when a domain expires today' do
    it 'sends an expiration notice' do
      expect do
        NotificationGroupsManager.send_expiration_reminders(db: 'ssl_com_test')
      end.to have_enqueued_job(ActionMailer::DeliveryJob).with(NotificationGroupMailer)
    end
  end
end

Тест, который должен «отправить уведомление о дайджесте домена», завершается неудачно со следующим сообщением:

expected to enqueue exactly 1 jobs, with [NotificationGroupMailer], but enqueued 0

Я прошел через код, который проверен. Соответствующий код находится здесь:

  scanned_certificates.each do |scanned_cert|
    expiration_date = scanned_cert.not_after.to_date
    if (Date.today == (expiration_date - reminders[0].day))
      expired_certificates << scanned_cert
      break
    elsif (Date.today == (expiration_date - reminders[1].day))
      expired_certificates << scanned_cert
      break
    elsif (Date.today == (expiration_date - reminders[2].day))
      expired_certificates << scanned_cert
      break
    elsif (Date.today == (expiration_date - reminders[3].day))
      expired_certificates << scanned_cert
      break
    elsif (Date.today == (expiration_date - reminders[4].day))
      expired_certificates << scanned_cert
      break
    end
  end

  if expired_certificates.any?
    NotificationGroupMailer.expiration_notice(ng, expired_certificates, contacts.pluck(:email_address).uniq, ssl_account).deliver_later
  end

Обычно я отправляю сообщение об истечении срока действия в соответствующее время. Когда я путешествую по коду с помощью byebug, я вижу, что выполняется метод deliver_later, но мой тест не проходит. Я включил ActiveJob::TestHelper в качестве модуля и поместил в свою среду / test.rb следующее:

config.action_mailer.perform_deliveries = true
  config.active_job.queue_adapter = :test

, но очередь по-прежнему не регистрирует, что почтовое сообщение было отправлено, хотя я может проверить это в разработке и пройти через byebug. Что-то мне не хватает?

...