Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-06-03 00:30:21 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-06-14 00:58:15 +0300
commit44d68159999a0ee30f7714470c1ef5b0c4a717fa (patch)
tree1969eaeeb5be1533271e26515d6953e6ab4eb058 /spec/support/login_helpers.rb
parent821fc4b03479a193b055c91b8a655d226bc46c17 (diff)
Allow login_as helper to accept a User object
Diffstat (limited to 'spec/support/login_helpers.rb')
-rw-r--r--spec/support/login_helpers.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb
index 791d2a1fd64..1bd68552012 100644
--- a/spec/support/login_helpers.rb
+++ b/spec/support/login_helpers.rb
@@ -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