gitlab-org--gitlab-foss/features/steps/shared/authentication.rb

76 lines
1.4 KiB
Ruby
Raw Normal View History

require Rails.root.join('features', 'support', 'login_helpers')
2012-09-10 11:35:03 -04:00
module SharedAuthentication
include Spinach::DSL
include LoginHelpers
step 'I sign in as a user' do
sign_out(@user) if @user
@user = create(:user)
sign_in(@user)
end
step 'I sign in via the UI' do
gitlab_sign_in(create(:user))
2012-09-10 11:35:03 -04:00
end
step 'I sign in as an admin' do
sign_out(@user) if @user
@user = create(:admin)
sign_in(@user)
end
2012-09-27 16:23:11 -04:00
2014-02-07 11:59:55 -05:00
step 'I sign in as "John Doe"' do
gitlab_sign_in(user_exists("John Doe"))
2014-02-07 11:59:55 -05:00
end
step 'I sign in as "Mary Jane"' do
gitlab_sign_in(user_exists("Mary Jane"))
2014-02-07 11:59:55 -05:00
end
step 'I should be redirected to sign in page' do
expect(current_path).to eq new_user_session_path
end
2014-06-26 03:49:14 -04:00
step "I logout" do
gitlab_sign_out
2014-06-26 03:49:14 -04:00
end
step "I logout directly" do
gitlab_sign_out
end
2012-09-27 16:23:11 -04:00
def current_user
@user || User.reorder(nil).first
2012-09-27 16:23:11 -04:00
end
private
def gitlab_sign_in(user)
visit new_user_session_path
fill_in "user_login", with: user.email
fill_in "user_password", with: "12345678"
check 'user_remember_me'
click_button "Sign in"
@user = user
end
def gitlab_sign_out
return unless @user
if Capybara.current_driver == Capybara.javascript_driver
find('.header-user-dropdown-toggle').click
click_link 'Sign out'
expect(page).to have_button('Sign in')
else
sign_out(@user)
end
@user = nil
end
2012-09-10 11:35:03 -04:00
end