想知道如何在RSpec中测试ActionMailer请求是否实际发送到了delayed_job队列。
我原本认为这很简单,但我的delayed_job队列似乎没有增加。以下是代码:
控制器:
def create
@contact = Contact.new(params[:contact])
if @contact.save
contactmailer = ContactMailer
contactmailer.delay.contact_message(@contact)
redirect_to(contacts_url)
else
render :action => "new"
end
规格:
it "queues mail when a contact is created" do
expectedcount = Delayed::Job.count + 1
Contact.stub(:new).with(mock_contact()) { mock_contact(:save => true) }
post :create, :contact => mock_contact
expectedcount.should eq(Delayed::Job.count)
end
在调用控制器之前和之后,Delayed::Job.count都返回0。我尝试将条件从控制器中去掉,但我仍然无法使延迟作业计数增加。
欢迎提出任何建议 - 谢谢!