gitlab-org--gitlab-foss/spec/support/login_helpers.rb

48 lines
1.1 KiB
Ruby
Raw Normal View History

module LoginHelpers
# Internal: Log in as a specific user or a new user of a specific 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
# Internal: Login as the specified user
#
# user - User instance to login with
def login_with(user)
visit new_user_session_path
2013-03-25 10:10:14 -04:00
fill_in "user_login", with: user.email
fill_in "user_password", with: "12345678"
click_button "Sign in"
Thread.current[:current_user] = user
end
2014-07-04 03:26:59 -04:00
# Requires Javascript driver.
def logout
2014-10-01 18:21:29 -04:00
find(:css, ".fa.fa-sign-out").click
end
# Logout without JavaScript driver
def logout_direct
page.driver.submit :delete, '/users/sign_out', {}
end
end