Skip to content

Commit

Permalink
It supports have_enqueud_mail matcher sub class of DeliveryJob.
Browse files Browse the repository at this point in the history
  • Loading branch information
yalab committed Mar 30, 2020
1 parent b2e51f9 commit 2b14818
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rspec/rails/matchers/have_enqueued_mail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def mail_job_message(job)
end

def legacy_mail?(job)
job[:job] == ActionMailer::DeliveryJob
job[:job] <= ActionMailer::DeliveryJob
end

def parameterized_mail?(job)
RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] == ActionMailer::Parameterized::DeliveryJob
RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? && job[:job] <= ActionMailer::Parameterized::DeliveryJob
end

def unified_mail?(job)
RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] == ActionMailer::MailDeliveryJob
RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? && job[:job] <= ActionMailer::MailDeliveryJob
end
end
# @api public
Expand Down
15 changes: 15 additions & 0 deletions spec/rspec/rails/matchers/have_enqueued_mail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ class UnifiedMailer < ActionMailer::Base
def test_email; end
def email_with_args(arg1, arg2); end
end

class SubClassDeliveryJob < ActionMailer::DeliveryJob
end

class SubClassUnifiedMailer < ActionMailer::Base
self.delivery_job = SubClassDeliveryJob

def test_email; end
end
end
end

Expand Down Expand Up @@ -397,6 +406,12 @@ def self.name; "NonMailerJob"; end
a_hash_including(params: {'foo' => 'bar'}, args: [1, 2])
)
end

it "passes subclass delivery_job" do
expect {
SubClassUnifiedMailer.test_email.deliver_later
}.to have_enqueued_mail(SubClassUnifiedMailer, :test_email)
end
end
end
end

0 comments on commit 2b14818

Please sign in to comment.