Allow login_as helper to accept a User object

This commit is contained in:
Robert Speicher 2015-06-02 17:30:21 -04:00
parent 821fc4b034
commit 44d6815999

View file

@ -1,9 +1,25 @@
module LoginHelpers
# Internal: Create and log in as a user of the specified role
# Internal: Log in as a specific user or a new user of a specific role
#
# role - User role (e.g., :admin, :user)
def login_as(role)
@user = create(role)
# user_or_role - User object, or a role to create (e.g., :admin, :user)
#
# Examples:
#
# # Create a user automatically
# login_as(:user)
#
# # Create an admin automatically
# login_as(:admin)
#
# # Provide an existing User record
# user = create(:user)
# login_as(user)
def login_as(user_or_role)
if user_or_role.kind_of?(User)
@user = user_or_role
else
@user = create(user_or_role)
end
login_with(@user)
end