Skip to content

Commit

Permalink
Merge pull request #2578 from rspec/have-enqueued-mail-fix
Browse files Browse the repository at this point in the history
Fix have_enqueued_mail with global id arguments
  • Loading branch information
JonRowe committed Mar 7, 2022
1 parent 4ded7a4 commit 6fd11ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rspec/rails/matchers/have_enqueued_mail.rb
Expand Up @@ -145,7 +145,7 @@ def deserialize_arguments(job)
if hash.key?("_aj_ruby2_keywords")
keywords = hash["_aj_ruby2_keywords"]

original_hash = keywords.each_with_object({}) { |new_hash, keyword| new_hash[keyword.to_sym] = hash[keyword] }
original_hash = keywords.each_with_object({}) { |keyword, new_hash| new_hash[keyword.to_sym] = hash[keyword] }

args + [original_hash]
elsif hash.key?(:args) && hash.key?(:params)
Expand Down
12 changes: 12 additions & 0 deletions spec/rspec/rails/matchers/have_enqueued_mail_spec.rb
Expand Up @@ -4,6 +4,12 @@
require "action_mailer"
require "rspec/rails/matchers/have_enqueued_mail"

class GlobalIDArgument
include GlobalID::Identification
def id; 1; end
def to_global_id(options = {}); super(options.merge(app: 'rspec-rails')); end
end

class TestMailer < ActionMailer::Base
def test_email; end
def email_with_args(arg1, arg2); end
Expand Down Expand Up @@ -418,6 +424,12 @@ def self.name; "NonMailerJob"; end
)
end

it "passes when given a global id serialised argument" do
expect {
UnifiedMailer.with(inquiry: GlobalIDArgument.new).test_email.deliver_later
}.to have_enqueued_email(UnifiedMailer, :test_email)
end

it "passes when using a mailer with `delivery_job` set to a sub class of `ActionMailer::DeliveryJob`" do
expect {
UnifiedMailerWithDeliveryJobSubClass.test_email.deliver_later
Expand Down

0 comments on commit 6fd11ab

Please sign in to comment.