我的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
Sessions Helper:
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
答案 0 :(得分:2)
我想你应该稍微改变你的代码:
def deny_access
redirect_to signin_path, :notice => "Please sign in to access this page." and return
end