From 6f029a8199ad71860650d446caec5daa43163506 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 7 Mar 2022 10:17:09 +0000 Subject: [PATCH] Add regression check for mailer with global job is and fix swapped argument bug --- lib/rspec/rails/matchers/have_enqueued_mail.rb | 2 +- spec/rspec/rails/matchers/have_enqueued_mail_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/rspec/rails/matchers/have_enqueued_mail.rb b/lib/rspec/rails/matchers/have_enqueued_mail.rb index 01ba0f4e7..f8c347cba 100644 --- a/lib/rspec/rails/matchers/have_enqueued_mail.rb +++ b/lib/rspec/rails/matchers/have_enqueued_mail.rb @@ -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) diff --git a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb index 80357c88d..10b8606ff 100644 --- a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb +++ b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb @@ -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 @@ -413,6 +419,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