预期的响应为<:redirect>但是< 200>

时间:2011-10-03 08:59:02

标签: ruby-on-rails rspec

我的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

1 个答案:

答案 0 :(得分:2)

我想你应该稍微改变你的代码:

def deny_access
  redirect_to signin_path, :notice => "Please sign in to access this page." and return
end