ticket_article_communicate_email_job_spec.rb 1.0 KB

12345678910111213141516171819202122232425262728
  1. require 'rails_helper'
  2. RSpec.describe TicketArticleCommunicateEmailJob, type: :job do
  3. describe '#perform' do
  4. context 'for an email article' do
  5. let(:article) { create(:ticket_article, type_name: 'email') }
  6. let(:recipient_list) { [article.to, article.cc].reject(&:blank?).join(',') }
  7. before { allow(Rails.logger).to receive(:info) }
  8. # What we _really_ want is to expect an email to be sent.
  9. # So why are we testing log messages instead?
  10. #
  11. # Because so far, our attempts to test email dispatch have either
  12. # a) been closely tied to implementation, with lots of ugly mock objects; or
  13. # b) had to test faraway classes like Channel::Driver::Imap.
  14. #
  15. # In other words, this test is NOT set in stone, and very open to improvement.
  16. it 'records outgoing email dispatch to Rails log' do
  17. described_class.perform_now(article.id)
  18. expect(Rails.logger)
  19. .to have_received(:info)
  20. .with("Send email to: '#{recipient_list}' (from #{article.from})")
  21. end
  22. end
  23. end
  24. end