没有填充ActionMailer :: Base.deliveries数组

时间:2012-01-13 19:42:42

标签: ruby-on-rails ruby-on-rails-3 actionmailer factory-bot

我正在尝试运行rspec测试。 您可以看到大部分代码here

也许它是相关的: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继承的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 = 'contact_me@test.com'
  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

1 个答案:

答案 0 :(得分:0)

哇。这真的很烦人。因为异常被吃掉了,我没有看到我错过了电子邮件主题的必要价值。