User.invite!不在测试中发送电子邮件

时间:2013-03-25 23:53:05

标签: ruby-on-rails ruby devise devise-invitable

我正在尝试为我的用户模型创建一些测试。当我使用devise_invitable User.invite邀请用户访问我的应用程序时!创建用户但似乎不记录电子邮件。 ActionMailer::Base.deliveries.count == 0。在生产中发送电子邮件,当我在测试中使用我的客户电子邮件时ActionMailer::Base.deliveries.count是正确的号码。

我是否在devise_invitable中缺少为测试配置电子邮件发送的内容?

2 个答案:

答案 0 :(得分:1)

我在测试和开发两个环境时遇到了同样的问题,并注意到它在日志中静默返回ArgumentError - An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.

我没有使用Devise::InvitationsController,因此在我的情况下调用confirm!是必要的,因为启用了:confirmable

User.invite!(invite_params, current_user) do |u|
  u.confirm!
end

devise_invitable(1.4.0)

答案 1 :(得分:0)

我相信这不是一个Devise的东西,默认情况下Rails在测试环境中实际上并不发送电子邮件,你可能有类似的行

# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test

在你的config / environments / test.rb上,为了实际发送电子邮件你可以评论这一行,并使用你的production.rb的ActionMailer配置,但是不推荐这样做,因为你可以使用ActionMailer :: Base .deliveries排列自己来测试你的电子邮件。

相关问题