0

我正在为发送多封电子邮件的邮件程序编写一些规范。邮件程序的控制器是:

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 请求时,由于某种原因它不发送电子邮件,所以我必须强制它。

当我创建发布请求时,有什么方法可以强制发送电子邮件?是否必须重复自己?

提前致谢!

4

1 回答 1

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
于 2013-10-12T05:04:14.987 回答