0
Я пытаюсь проверить, что письма отправляются в after_create обратного вызова объектаКак я могу проверить, что электронная почта была отправлена после создания объекта
class Payment < ActiveRecord::Base
#associations
belongs_to :quotation
#validations
validates :method, :amount, :quotation, :presence => true
#callbacks
after_create :send_email_confirmations
def method_enum
[['Cash'],['Bank Transfer'], ['PayPal']]
end
private
def send_email_confirmations
UsersMailer.confirm_payment(self).deliver
AdminsMailer.payment_received(self).deliver
end
end
Test File:
require 'spec_helper'
describe Payment do
describe AdminsMailer do
before :each do
Admin.delete_all
User.delete_all
@quotation = FactoryGirl.create(:quotation)
@submission = @quotation.submission
@payment = Payment.new(:method => 'paypal', :amount => @quotation.price, :transaction_id => '4543332', :quotation_id => @quotation.id)
end
it "should deliver the admin email payment email" do
@payment.save
AdminsMailer.should_receive(:payment_received).with(@payment)
end
end
end
Этот дает следующий результат:
Failure/Error: AdminsMailer.should_receive(:payment_received).with(@payment)
(<AdminsMailer (class)>).payment_received(#<Payment id: 54, method: "paypal", amount: #<BigDecimal:7fabd1e449c0,'0.5E3',9(36)>, transaction_id: "4543332", created_at: "2013-09-27 11:30:53", updated_at: "2013-09-27 11:30:53", quotation_id: 58>)
expected: 1 time
Как я могу проверить, что электронные письма отправлены?
received: 0 times
Я последовал твоему совету. Спасибо, что отправили меня на правильный путь. – chell
Я использовал Object.any_instance.should_receive (: payment_received), а затем – chell
@payment = Payment.save – chell