0
Rails 2.3.8 프로젝트에서 Devise 1.0.8을 사용하고 있습니다.current_user는 Devise를 사용하는 컨트롤러에서 User 대신 TrueClass를 반환합니다.
context "when current_user is admin" do
should "render" do
sign_in Factory(:admin)
get :index
assert_response :success
end
end
을 그리고 컨트롤러 자체에서 다음 before_filter있다 : 내 컨트롤러 테스트에서 나는이
true
false
NoMethodError: undefined method `admin?' for true:TrueClass
그래서 CURRENT_USER입니다 : 이것은 내 테스트의 출력이
def redirect_if_not_admin
puts current_user
redirect_to root_path unless current_user.try(:admin?)
end
입니다 테스트에서 sign_in을 사용할 때 true입니다. 그러나 내가하지 않으면 current_user는 nil이므로 확실히 영향을받습니다. 모든 도움을 미리 감사드립니다.