Skip to content

Instantly share code, notes, and snippets.

@cblunt
Created February 27, 2012 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cblunt/1923853 to your computer and use it in GitHub Desktop.
Save cblunt/1923853 to your computer and use it in GitHub Desktop.
Handy helper methods for RSpecs, e.g. logging in as a user.
# spec/support/spec_support.rb
def login_as(user = nil)
user ||= Factory.create(:user)
session[:user_id] = user.id
end
def current_user
User.find(session[:user_id])
rescue
nil
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment