2012-02-25 3 views
0

ApplicationController 메소드 인 logged_in?이 사용자를 반환하기를 원하기 때문에 스펙이 실패합니다.RSpec :보기에서 컨트롤러 메소드 스텁

사양을 지정하는 방법을 잘 모르겠습니다. 현재 before(:each)에서 내가 가진 :

Failure/Error: render 
ActionView::Template::Error: 
    undefined method 'logged_in?' for #<#<Class:0x007f9c908e4b10>:0x007f9c90873b68> 

FWIW : 작동하지 않는

controller.stub!(:logged_in?).and_return(FactoryGirl.create(:active_user)) 
@ballots = FactoryGirl.create_list(:full_ballot, 2) 

:active_user:full_ballot

업데이트에 연결되어있는 사용자의 사용자 공장 : 요청한대로 :

class ApplicationController < ActionController::Base 
    ... 
    def current_user 
    @current_user ||= User.find(cookies[:id_token]) if cookies[:id_token] 
    end 

    def logged_in? 
    current_user 
    end 
    ... 
end 
+0

'current_user' 및'logged_in? '메소드를 게시 할 수 있습니까? – James

답변

2

devise test helpers가 어떻게되는지보십시오. 테스트 전에이 메소드를 정의 할 수있는 것처럼 보입니다 :

def logged_in? 
    FactoryGirl.create :active_user 
end 
+0

위대한 작품! 다른 접근법이 있는지보기 위해 몇 시간 동안 열어 두십시오. – Meltemi

관련 문제