redirect_to browse_path(asset.parent_id), notice: "successfully created file!", status: 201
201是应该在创建资源时设置的状态。虽然上述方法适用于创建操作,其行为规范不再做:设置http状态代码
subject { response }
describe '.create' do
context 'when orphan' do
before do
post :create, asset: { parent_id: nil, uploaded_file: file }
end
it { should have_http_status 201 }
it { should redirect_to '/' }
end
end
状态期望通过,但redirect_to的期望失败:
Expected response to be a <redirect>, but was <201>
我承认,它不再一个302重定向,但它仍然将用户重定向到一个新的路由(我想测试)。该redirect_to的规范通过,如果我将它设置为302的“错误”的代码,而不是201:
redirect_to browse_path(asset.parent_id), notice: "successfully created file!", status: 302
所以我应该与设置状态代码烦恼呢?我承认我实际上并不知道浏览器如何使用它们,并且我的应用程序的功能同样如此,如果我刻意将它们设置在我的操作中或不这样做(仅使用302重定向和200次成功)。
如果状态码很重要,应该如何让我的上述规格通过?
我得到'错误数量的参数(2为1)'? – Starkers