2017-05-23 1 views
0

컨트롤러에서 사용하고있는 모델 메서드를 스텁하려는 중이지만 작동하지 않는 것 같습니다. 누군가가 나 그것을rspec 컨트롤러 테스트를위한 모델 메서드 스텁 방법

사용자 컨트롤러

if current_user.user_token 
     @user = @account.users.find(params[:id]) 
     @user.revoke_seat(:admin, current_user) 
     render :template => "/admin/users/revoke_seat" 
    else 
     render :js => "window.location.href='#{server_url}/oauth/authorize?response_type=code&client_id=#{client_id}&state=#{request.referrer}?auto_revoke_seat=true&redirect_uri=#{auth_service_callback_url}"; 
    end 

RSpec에

before do 
    users(:admin).stub(:internal_admin?).and_return(true) 
    login_as :admin 
    user.stub(:user_token).and_return("123123")# THIS IS NOT WORKING 
    end 

    it "should redirect to authentication service to generate access token" do 
     expect(user).to receive(:user_token).and_return(true) 
     xhr :put, :revoke_seat, account_id: account.id, id: user.id 
     expect(response).to render_template('admin/users/revoke_seat') 
     expect(assigns(:account)).to eq(account) 
     expect(assigns(:user)).to eq(user) 
    end 

답변

0

당신은 대신 stuballow 접근 방법을 시도 할 수 있습니다 할 수있는 적절한 방법을 알려 수 있습니다. 예 : allow(:admin).to receive(:internal_admin?).and_return(true)

관련 문제