Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7960709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:49:54+00:00 2026-06-04T04:49:54+00:00

I have a Rails 3.2.3 application and I am using MiniTest and Capybara to

  • 0

I have a Rails 3.2.3 application and I am using MiniTest and Capybara to run my integration tests. I rolled my own authentication and created a current_user helper_method in my application_controller.rb.

My application layout file only displays certain links, like logout, etc., when a 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 the browser, but not in my test. “current_user” ends up being nil.

I am new to BDD, but is there something that prevents sessions from being created during tests? What am I missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:49:55+00:00Added an answer on June 4, 2026 at 4:49 am

    NOTE: helper methods defined in controllers are not included.

    from here.

    The solution is to organize them in a dedicated helper class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple API for a Rails application using token-based-authentication that supports
I have a Rails 3.2.2 application using Ruby version 1.9.2. I have created basic
I have created a blog application using Ruby on Rails which includes the ability
I have recently started using RSpec for Integration testing in my Rails application, to
I have a Rails application using Restful authentication and declarative authorization. I have some
I have created a pdf version of our rails application using the Prawn plugin,
I am running my tests for a rails application using test/unit and capybara. I
I'm writing an integration test for a rails application using Capybara within Rspec. After
I have a perfectly working rails application including devise authentication. I created a second
I have a Rails 3 application using Devise for authentication. In addition to the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.