预期响应为 <:redirect>但是是<200> [英] Expected response to be a <:redirect> but was <200>
本文介绍了预期响应为 <:redirect>但是是<200>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 rspec 测试遇到了问题,在查看了之前的问题后,我一直无法解决.测试失败并出现上述错误,但代码在实践中有效,有人知道如何解决吗?
I've got an issue with my rspec tests and having looked through previous questions I haven't been able to resolve it. The test fails with the above error but the code works in practice, does anyone know how to resolve this?
Rspec:
describe "authentication of edit/update pages" do
before(:each) do
@user = Factory(:user)
end
describe "for non-signed in users" do
it "should deny access to 'edit'" do
get :edit, :id => @user
response.should redirect_to(signin_path)
end
it "should deny access to 'update'" do
put :update, :id => @user, :user => {}
response.should redirect_to(signin_path)
end
end
end
会话助手:
def deny_access
redirect_to signin_path, :notice => "Please sign in to access this page."
end
用户控制器
class UsersController < ApplicationController
before_filter :authenticate, :only => [:edit, :update]
private
def authenticate
deny_access unless signed_in?
end
end
推荐答案
我想你应该稍微修改一下代码:
I guess you should change your code a bit:
def deny_access
redirect_to signin_path, :notice => "Please sign in to access this page." and return
end
这篇关于预期响应为 <:redirect>但是是<200>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文