assert_enqueued_email_with sets the default queue to
Given we know what the queue will be (we can check the config) we can remove this from the method attributes and pass it internally.
# def assert_enqueued_email_with(mailer, method, args: nil, queue: "mailers", &block) # original with 'queue' attribute def assert_enqueued_email_with(mailer, method, args: nil, &block) args = if args.is_a?(Hash) [mailer.to_s, method.to_s, "deliver_now", params: args, args: ] else [mailer.to_s, method.to_s, "deliver_now", args: Array(args)] end # real solution will need to handle queue_name_prefix and queue_name_delimiter queue = Rails.configuration.active_job.deliver_later_queue_name assert_enqueued_with(job: mailer.delivery_job, args: args, queue: queue, &block) end
My motivation is based on getting stuck writing a test where I couldn’t work out why it wasn’t passing. It took me a long time to work out that the project had customised the mailer queue. I love Rails for how it goes out of its way to help ie. if it knows what the queue name is, you shouldn’t have to provide it. Happy to proceed with a contribution if you think it will help?
One question: Is it possible to do this in a way that preserves backwards compatibility? I don’t think there is but perhaps there’s something I’m unaware of. Otherwise, would we push a deprecation warning?