ActionMailer::Base.deliveries 数组未填充

发布于 2024-12-26 15:30:01 字数 2422 浏览 0 评论 0原文

我正在尝试运行 rspec 测试。 您可以在此处查看大部分代码。

也许它是相关的:CoRegEmailWorker.perform包含这个:

ProvisionalUser.where("unsubscribed = false AND disabled = false AND (email_sent_count < ? OR email_sent_count is NULL) AND (last_email_sent <= ? OR last_email_sent IS NULL) AND sign_up_date IS NULL",
                      ProvisionalUser::EMAIL_COUNT_LIMIT, email_sending_interval.hours.ago).
                each{ |user|
  begin
    user.send_email
  rescue Exception => ex
    logger.error ex
  end
}

并且ProvisionalUser有这个方法:

  def send_email
    self.email_sent_count = self.email_sent_count.nil? ? 1 : self.email_sent_count + 1
    self.last_email_sent = DateTime.now
    self.disabled = true if self.email_sent_count == EMAIL_COUNT_LIMIT
    self.save!

    ProvisionalUserNotifier.send_registration_invite(self.id).deliver
  end

最后,ProvisionalUserNotifier继承自MailGunNotifier,而MailGunNotifier继承自ActionMailer

我遇到的问题是交付数组没有被填充。在我的“config/environments/test.rb”中。我有这个:

config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :test

我不确定这里还需要什么。

我什至尝试过这个:

require "spec_helper"
require "action_mailer"

describe "unsubscribe functionality" do

  pu1 = ProvisionalUser.new
  pu1.email = '[email protected]'
  pu1.partner = 'partner'
  pu1.first_name = 'joe'
  pu1.save!

  before(:each) do
    ActionMailer::Base.delivery_method = :test
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.deliveries = []
  end

  it "should send emails to subscribed users only" do
    unsubscribed_user = FactoryGirl.build(:unsubscribed_user)
    unsubscribed_user.save!

    subscribed_user = FactoryGirl.create(:subscribed_user)
    CoRegEmailWorker.perform
    ActionMailer::Base.deliveries.length.should == 1
    ActionMailer::Base.deliveries.first.email.should =~ subscribed_user.email
    #sent.first.email.should_not =~ unsubscribed_user.email
    #sent.first.email.should =~ subscribed_user.email
  end

  def sent
    ActionMailer::Base.deliveries
  end

end

I'm trying to run an rspec test.
You can see most of that code here.

Maybe it's relevant: CoRegEmailWorker.perform contains this:

ProvisionalUser.where("unsubscribed = false AND disabled = false AND (email_sent_count < ? OR email_sent_count is NULL) AND (last_email_sent <= ? OR last_email_sent IS NULL) AND sign_up_date IS NULL",
                      ProvisionalUser::EMAIL_COUNT_LIMIT, email_sending_interval.hours.ago).
                each{ |user|
  begin
    user.send_email
  rescue Exception => ex
    logger.error ex
  end
}

and ProvisionalUser has this method:

  def send_email
    self.email_sent_count = self.email_sent_count.nil? ? 1 : self.email_sent_count + 1
    self.last_email_sent = DateTime.now
    self.disabled = true if self.email_sent_count == EMAIL_COUNT_LIMIT
    self.save!

    ProvisionalUserNotifier.send_registration_invite(self.id).deliver
  end

Finally, ProvisionalUserNotifier inherits from MailGunNotifier which inherits from ActionMailer.

The problem I'm having is that the deliveries array is not being populated. In my `config/environments/test.rb'. I have this:

config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :test

I'm not certain what else is needed here.

i've even gone so far as to try this:

require "spec_helper"
require "action_mailer"

describe "unsubscribe functionality" do

  pu1 = ProvisionalUser.new
  pu1.email = '[email protected]'
  pu1.partner = 'partner'
  pu1.first_name = 'joe'
  pu1.save!

  before(:each) do
    ActionMailer::Base.delivery_method = :test
    ActionMailer::Base.perform_deliveries = true
    ActionMailer::Base.deliveries = []
  end

  it "should send emails to subscribed users only" do
    unsubscribed_user = FactoryGirl.build(:unsubscribed_user)
    unsubscribed_user.save!

    subscribed_user = FactoryGirl.create(:subscribed_user)
    CoRegEmailWorker.perform
    ActionMailer::Base.deliveries.length.should == 1
    ActionMailer::Base.deliveries.first.email.should =~ subscribed_user.email
    #sent.first.email.should_not =~ unsubscribed_user.email
    #sent.first.email.should =~ subscribed_user.email
  end

  def sent
    ActionMailer::Base.deliveries
  end

end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2025-01-02 15:30:01

哇。这真的很烦人。因为例外情况是被吃掉,所以我没有发现我遗漏了电子邮件主题正常工作所需的值。

wow. that was really annoying. because the exception was being eaten, i wasn't seeing that I was missing a neccessary value for the subject of the email to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文