Skip to content

[BUG] Noticed::DeliveryMethods::Email does not support keyword arguments #564

@tcannonfodder

Description

@tcannonfodder

Bug Report

Describe the Bug:

ActionMailers that use keyword arguments in their methods are not able to be used in Noticed because there is not support for keyword arguments.

Example mailer:

class User::EmergencyPasskeyRegistrationMailer < ApplicationMailer

  def emergency_registration_request(emergency_passkey_registration:)
    user = emergency_passkey_registration.user
    token = emergency_passkey_registration.generate_token_for(:emergency_registration)
# ...

To Reproduce:

  1. Step 1
  2. Step 2
  3. ...

Expected Behavior:
These mailers should work, since keyword arguments are a common Ruby feature

Possible Fix:

I've got the following override from a patched subclass I made, submitting as a PR shortly.

def deliver
    mailer = fetch_constant(:mailer)
    email = evaluate_option(:method)
    args = evaluate_option(:args) || []
    kwargs = evaluate_option(:kwargs) || {}

    mailer_instance = mailer.with(params)

    if kwargs.present?
      mail = mailer_instance.public_send(email, **kwargs)
    else
      mail = mailer_instance.public_send(email, *args)
    end
    (!!evaluate_option(:enqueue)) ? mail.deliver_later : mail.deliver_now
  end

Checklist:

  • I have searched for similar issues and couldn't find any
  • I have checked the documentation for relevant information
  • I have included all the required information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions