Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix have_enqueued_mail with global id arguments #2578

Merged
merged 1 commit into from Mar 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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
Expand Down