我正在为发送多封电子邮件的邮件编写一些规范。 邮件的控制者是:
def create
@message = Message.new(params[:message])
if @message.valid?
@message.email.each do |email|
MessageMailer.new_message(@message, email).deliver
end
redirect_to users_index_path, :notice => "Email sent correctly"
else
notice = "There was an error"
render :new
end
end
和规范:
describe "POST 'create' for a diffusion" do
it "returns http success" do
@diffusion = Fabricate.build(:diffusion)
post 'create', message: @diffusion
response.should be_success
@before_send = ActionMailer::Base.deliveries.size
@diffusion.email.each do |email|
MessageMailer.new_message(@diffusion, email).deliver
end
ActionMailer::Base.deliveries.size.should eq @before_send + @diffusion.email.size
end
end
问题是当我创建Post请求时,由于某种原因它不发送电子邮件,所以我必须强制它。
在创建帖子请求时,有没有办法强制发送电子邮件?重复自己是强制性的吗?
提前致谢!
答案 0 :(得分:0)
我认为如果您在发布到@before_send
之前抓取create
,它应该有用。
describe "POST 'create' for a diffusion" do
it "returns http success" do
@diffusion = Fabricate.build(:diffusion)
@before_send = ActionMailer::Base.deliveries.size
post 'create', message: @diffusion
response.should be_success
ActionMailer::Base.deliveries.size.should eq @before_send + @diffusion.email.size
end
end