A More Useful login_as Test Helper

I just got upset that i could not do login_as User.first or User.first.id, so i fixed that…

Usage

#in your tests...
login_as :quentin
login_as false
login_as User.first
login_as User.first.id + 1

Install

#authenticated_test_helper
  def login_as(user)
    id = case user
      when false,nil then nil
      when Symbol,String then users(user).id
      when Fixnum then user
      else user.id
    end
    @request.session[:user_id] = id
  end
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s