Hi I have some protected methods in my application controller to handle
logging in users and Id like to be able to use them in my tests. But
whenever I try to run my tests i always get errors E.g.
NameError: undefined local variable or method `logged_in_user’ for
#DashboardControllerTest:0x7f32bb483cb8
how do i get round this. Heres some code -
class ApplicationController < ActionController::Base
protected
def logged_in_user?
@logged_in_user = User.find(session[:user]) if session[:user]
end
def logged_in_user=user
if !user.nil?
session[:user] = user
@logged_in_user = user
end
end
def logged_in_user
if logged_in_user?
return @logged_in_user
end
end
end
and my testfile
require ‘test_helper’
require ‘application_controller’
class DashboardControllerTest < ActionController::TestCase
fixtures :users
test “welcome page” do
get :welcome
assert_response :success
end
test “logged in user can access dashboard” do
assert logged_in_user, users(:valid_user)
get :welcome
assert_response :success
end
end