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…


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


  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
    @request.session[:user_id] = id

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 )

Facebook photo

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

Connecting to %s