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 992759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:19:04+00:00 2026-05-16T06:19:04+00:00

I’m working on a Rails application that requires you to be logged in to

  • 0

I’m working on a Rails application that requires you to be logged in to see pretty much anything. For unit tests, this isn’t a problem since they interact with the model directly. For integration tests, this isn’t a big problem since I can just have the appropriate user log in via Rails’ post method. It seems like it makes sense to put all rights-sensitive tests in the integration tests (e.g., test that a user cannot edit someone else’s comments).

However, I run into issues when handling the functional tests. It seems like it makes sense for me to test functionality that does not hinge crucially on user status (other than in its ability act as a gateway) independently of user rights. Now, I can’t figure out a good way to do this, since all requests bounce the test client to the login page.

An inelegant solution I tried would be to put this log in request in the setup method, but the Rails tester tried to access an action, instead of a path. In particular, I had

def setup
  post /sessions/create, {:username => 'testdbadmin', :password => 'password}
end

But according to the logs, it just tried to access SomeController#/sessions/create, which is clearly not the intention.

I feel like I’m missing some big, built-in way to do this. Please advise.

  • 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-05-16T06:19:04+00:00Added an answer on May 16, 2026 at 6:19 am

    I do this in my functional tests by just setting valid logged-in session data in my setup, effectively simulating a request where a user has already authenticated (or hasn’t, as the case may be).

    I have a helper method in my test_helper.rb:

    def login(typ = :user, options = {})
        user = Factory.create(typ, {:username => "Joe"}.merge(options))
        session["user_id"] = user.id.to_s
      end
    

    And then in my functional test:

    class AccountsControllerTest < ActionController::TestCase
      context "Fresh session" do
        setup do
          @user = Factory.create(:user)
        end
    
        should "be redirected to the login page if not logged in" do
          get :show
          assert_redirected_to login_path
        end
    
      context "Logged in user with profile" do
        setup do
          @user = login
        end
    
        should "get the account home page" do
          get :show
          assert_response :success
        end
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.