我正在为发送多封电子邮件的邮件程序编写一些规范。邮件程序的控制器是:
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 请求时,由于某种原因它不发送电子邮件,所以我必须强制它。
当我创建发布请求时,有什么方法可以强制发送电子邮件?是否必须重复自己?
提前致谢!