我有一个用户模型的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.
Run Code Online (Sandbox Code Playgroud)
我确实将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
Run Code Online (Sandbox Code Playgroud)