debian-mirror-gitlab/spec/support/login_helpers.rb

54 lines
1.3 KiB
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
module LoginHelpers
2015-09-11 14:41:01 +05:30
# Internal: Log in as a specific user or a new user of a specific role
2014-09-02 18:07:02 +05:30
#
2015-09-11 14:41:01 +05:30
# 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
2014-09-02 18:07:02 +05:30
login_with(@user)
end
# Internal: Login as the specified user
#
# user - User instance to login with
# remember - Whether or not to check "Remember me" (default: false)
def login_with(user, remember: false)
2014-09-02 18:07:02 +05:30
visit new_user_session_path
fill_in "user_login", with: user.email
fill_in "user_password", with: "12345678"
check 'user_remember_me' if remember
2014-09-02 18:07:02 +05:30
click_button "Sign in"
Thread.current[:current_user] = user
end
# Requires Javascript driver.
def logout
2015-04-26 12:48:37 +05:30
find(:css, ".fa.fa-sign-out").click
2014-09-02 18:07:02 +05:30
end
2015-09-11 14:41:01 +05:30
# Logout without JavaScript driver
def logout_direct
page.driver.submit :delete, '/users/sign_out', {}
end
2015-09-25 12:07:36 +05:30
def skip_ci_admin_auth
allow_any_instance_of(Ci::Admin::ApplicationController).to receive_messages(authenticate_admin!: true)
end
2014-09-02 18:07:02 +05:30
end