开发者

Rspec with multi button form

I am building a simple blog in rails and have a form with multiple buttons. One button allows someone to save a draft, and another allows someone to publish a post.

One button has a name for saving the draft, and another has a name to publish the post. If the publish param is present, it will execute the publi开发者_JAVA技巧sh function in the post model.

In the controller I have

post.publish unless !params[:publish]

How do I use rspec to test that if the publish param is present that it will call the publish action on the model?


Well, it depends. If you do integration testing using capybara, you just say which button shall be clicked. But I guess, you have a controller. So instead of

post :create, :post => {...}

you need to do

post :create, :post => {...}, :publish => "Publish"

In reality, the value (label) of the button will be submitted as the value of params[:publish], so you might want to pass the real label of that button as :publish.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜