mailer.deliver_now无法在测试环境中序列化对象

问题描述 投票:0回答:1

在rails6中,我们通过参数化邮件从Mailer.deliver_now切换到Mailer.deliver_later。

#environments/test.rb
config.action_mailer.delivery_method = :test
config.active_job.queue_adapter = :inline # is this neccessary?


# model.rb
def send_mail 
    WithdrawalMailer.with(address: self).confirm_address.deliver_later
end

在开发中,一切都很好,但是在测试环境中,这失败了,因为他无法序列化对象。

 1) Asset withdrawals .process_withdrawals! starts the process
     Failure/Error: WithdrawalMailer.with(address: self).confirm_address.deliver_later
     ActiveJob::SerializationError:
     Unable to serialize Wallet::WithdrawalAddress without an id. (Maybe you forgot to call save?)
     # ./app/models/wallet/withdrawal_address.rb:60:in `send_confirmation_email'

如何使.deliver_later在测试环境中工作?

ruby-on-rails rspec actionmailer ruby-on-rails-6
1个回答
0
投票

after_commit中而不是在before_create中发送邮件的呼叫,它可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.