开发者

Expected response to be a <:redirect> but was <200>

开发者 https://www.devze.com 2023-04-09 22:25 出处:网络
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

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_开发者_Python百科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

Users Controller

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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号