I have a Rails 3.2.3 application and I use MiniTest and Capybara to run my integration tests. I performed my own authentication and created the current helper_method_server in my application application_controller.rb.
In my application layout file, only certain links are displayed, for example, logging out, etc., when the user is logged in.
But the current_user method does not work during tests. It looks like this:
class ApplicationController < ActionController::Base protect_from_forgery private def authenticate if current_user.blank? redirect_to root_url, :alert => "You must first log in." end end def authenticate_admin unless current_user and current_user.admin? redirect_to root_url, :alert => "You must be logged in as an administrator to access this feature." end end def current_user begin @current_user ||= User.find(session[:user_id]) if session[:user_id] rescue nil end end helper_method :current_user end
So in my application.html.erb file there is:
<% unless current_user.blank? %> <li><%= link_to logout_path %></li>
So this works when I test it through a browser, but not in my test. "current_user" ends with zero.
I'm new to BDD, but is there something that prevents session creation during tests? What am I missing?
AKWF source share