Question

View spec failing because the ApplicationController method, logged_in?, wants a user to be returned.

Not sure how to spec this. Currently in before(:each) I have:

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

which isn't working:

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

FWIW: :active_user is the user factory for the user that is attached to the :full_ballot

Update: As requested:

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
Was it helpful?

Solution

See how devise test helpers do it. It looks like you can define this method before tests and it should work:

def logged_in?
   FactoryGirl.create :active_user
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top