Rails - redirect_to(request.referer) 的功能测试
也许我又只见树木不见森林了,但我似乎无法找到一种方法来编写一个功能测试来测试重定向到 request.referer 的 :destroy 操作。
代码是:
def destroy
@step = Step.find(params[:id])
@step.destroy
respond_to do |format|
format.html { redirect_to(request.referer) }
format.xml { head :ok }
end
end
失败的测试是:
test "should destroy step" do
assert_difference('Step.count', -1) do
delete :destroy, :id => @step.to_param
end
assert_redirected_to request.referer
end
也没有运气使用:
redirect_to(:back)
...。
Maybe I just missing the forest for the trees again, but I can't seem to figure out a way to write a functional test that tests a :destroy action that redirects to request.referer.
Code is:
def destroy
@step = Step.find(params[:id])
@step.destroy
respond_to do |format|
format.html { redirect_to(request.referer) }
format.xml { head :ok }
end
end
Failing test is:
test "should destroy step" do
assert_difference('Step.count', -1) do
delete :destroy, :id => @step.to_param
end
assert_redirected_to request.referer
end
Having no luck using:
redirect_to(:back)
... as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
知道了。
通过测试的是:
感谢以下帮助: 我该怎么办在 Rails 中测试时设置 HTTP_REFERER?
Got it.
Passing test is:
Thanks to help from: How do I set HTTP_REFERER when testing in Rails?
您编写集成测试并使用应遵循重定向的delete_via_redirect之一。您可能还需要设置 HTTP_REFERER 标头 - 请参阅guide.rubyonrails.org
you write an integration test and use one of delete_via_redirect which should follow the redirect. You may also have to set the the HTTP_REFERER header - see guide.rubyonrails.org