【发布时间】:2013-12-02 14:57:40
【问题描述】:
我有一个用户模型的 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/environments/test.rb 中将 config.action_mailer.delivery_method 设置为 :test。为什么它在测试环境中尝试使用 SMTP?为什么仅此电子邮件交付(模型中)会发生这种情况,而其他交付(使用 devise gem)不会发生这种情况?
这是来自 User 模型的 sn-p:
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
【问题讨论】:
标签: ruby-on-rails rspec capybara actionmailer