我的 rspec 测试遇到问题,浏览了之前的问题后我无法解决它。测试失败并出现上述错误,但代码在实践中有效,有谁知道如何解决这个问题?
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
我想你应该稍微改变你的代码:
def deny_access
redirect_to signin_path, :notice => "Please sign in to access this page." and return
end
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)