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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:32:28+00:00 2026-05-11T18:32:28+00:00

I started writing functional tests for my rails app today. I use the RESTful

  • 0

I started writing functional tests for my rails app today. I use the RESTful authentication plugin. I ran into a couple confusing things I hope someone can clarify for me.

1) I wrote a quick login function because most of the functions in my rails app require authentication.

def login_as(user)
   @request.session[:user_id] = user ? user.id : nil
end

The issue I see with this function, is it basically fakes authentication. Should I be worried about this? Maybe it is okay to go this route as long as I test the true authentication method somewhere. Or maybe this is terrible practice.

2) The second confusing thing is that in some places in my functional tests, I need the full authentication process to happen. When a user is activated, I have the do_activate method create some initial objects for the user. It is analogous to the creation of a blank notebook object and pen object for a student application, if that makes sense.

So in order to properly test my application, I need the user to hit that activation state so those objects are created. I am currently using Factory Girl to create the user, and then calling the login_as function above to fake authentication.

I guess another option would be to skip the full authentication sequence and just create the blank objects with Factory Girl. I could test the proper authentication somewhere else.

What do you think? If I should go through the proper sequence, why isn’t the code below invoking the do_activate function?

user = Factory.create(:user)
user.active = 1
user.save

Thank you!

  • 1 1 Answer
  • 1 View
  • 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-11T18:32:28+00:00Added an answer on May 11, 2026 at 6:32 pm

    Faking it is perfectly acceptable.

    However, write other tests that ensure that the things you want protected are protected. So

    test "it should show the profile page" do
      user = Factory(:user)
      login_as(user)
      get :show, :id => user
      assert_response :success
    end
    
    test "it should not show the profile page cos I'm not logged in" do
      user = Factory(:user)
      get :show, :id => user
      assert_response :redirect
    end
    

    Feel free to hit me up for followups!

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

Sidebar

Related Questions

I'm writing an application that can be started either as a standard WinForms app
When I started writing database queries I didn't know the JOIN keyword yet and
I have just started writing my own JavaScript Framework (just for the learning experience),
What are some resources for getting started writing a Firefox Addon? Is there an
In my free time I started writing a small multiplayer game with a database
I am trying to get started writing scalable, telecom-grade applications with Asterisk and Ruby.
After using AS2 for several years, I'm getting started with writing applications in AS3
Well, after a long time writing .net programs in C# I started to feel
I started an application in Google App Engine right when it came out, to
I’ve been writing unit tests in strongly typed languages and I have a fair

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.