我有一个 Controller 操作,可以将电子邮件的发送排入队列。我为该 Controller 操作编写了一个测试,当我运行测试时,我收到了弃用警告:
DEPRECATION WARNING: Sending mail with DeliveryJob and Parameterized::DeliveryJob is deprecated and will be removed in Rails 6.1. Please use MailDeliveryJob instead.
Controller :
def send_email
SubscriptionMailer.with(user_id: @user.id).send_welcome_email.deliver_later
end
SubscriptionMailer:
class SubscriptionMailer < ApplicationMailer
helper :auxiliaries
before_action { @user = User.find_by(id: params[:user_id]) }
def send_welcome_email
@base_email = find_base_email_or_raise("welcome_email")
@subject = "#{@user.fname} #{@base_email.subject}"
send_email(subject: @subject)
end
end
测试:
test "#send_email should enqueue SubscriptionMailer's #send_welcome_email" do
assert_emails 1 do
get send_email_admin_subscriptions_activation_path(
@user.id,
)
end
end
如何升级我的应用程序以消除警告?
我已经read about在不同帖子中取消注释 new_framework_defaults_6_0.rb
中的一行,但这并没有解决问题。
最佳答案
要修复弃用警告,请将此行添加到 application.rb
:
config.action_mailer.delivery_job = "ActionMailer::MailDeliveryJob"
来源: https://github.com/rails/rails/issues/37068#issuecomment-545531362
问:这是否会影响电子邮件的传递方式?
该方法的参数已更改:
# DeliveryJob
def perform(mailer, mail_method, delivery_method, *args)
# MailDeliveryJob
def perform(mailer, mail_method, delivery_method, args:, params: nil)
因此,您可能必须在适用的情况下更改方法调用中的参数。
您可以找到有关此 PR 的更多详细信息:https://github.com/rails/rails/pull/34591
关于ruby-on-rails - Rails DeliveryJob 弃用警告 : How to upgrade to MailDeliveryJob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68638835/