我有一个用户模型的after_create回调,它将向管理员发送一封电子邮件,以便他可以批准该帐户.它在开发模式下完美运行,但是当我运行我的Capybara/RSpec测试时,它失败并出现以下异常:
ArgumentError: An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.
我确实将config.action_mailer.delivery_method设置为:test in config/environments/test.rb.为什么它在测试环境中尝试使用SMTP?为什么这只发生在这个电子邮件传递(在模型中)但不与其他传递(使用设计宝石)?
以下是User模型的代码段:
class User < ActiveRecord::Base after_create :send_admin_mail protected def send_admin_mail puts ActionMailer::Base.delivery_method #prints test! ReviewMailer.new_user_waiting_for_approval(self).deliver end end
jvnill.. 5
错误说你错过了一个to
地址.由于您正在向管理员发送电子邮件,我猜这封电子邮件根据Rails环境而有所不同,您可以在某处配置此电子邮件.确保为测试环境配置了一个.
错误说你错过了一个to
地址.由于您正在向管理员发送电子邮件,我猜这封电子邮件根据Rails环境而有所不同,您可以在某处配置此电子邮件.确保为测试环境配置了一个.