2017-03-29 16:46:13 -04:00
|
|
|
require Rails.root.join('features', 'support', 'login_helpers')
|
2012-09-10 11:35:03 -04:00
|
|
|
|
|
|
|
module SharedAuthentication
|
|
|
|
include Spinach::DSL
|
|
|
|
include LoginHelpers
|
|
|
|
|
2014-09-21 17:40:22 -04:00
|
|
|
step 'I sign in as a user' do
|
2017-03-29 16:46:13 -04:00
|
|
|
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
|
2012-09-25 20:11:57 -04:00
|
|
|
|
2014-09-21 17:40:22 -04:00
|
|
|
step 'I sign in as an admin' do
|
2017-03-29 16:46:13 -04:00
|
|
|
sign_out(@user) if @user
|
|
|
|
|
|
|
|
@user = create(:admin)
|
|
|
|
sign_in(@user)
|
2012-09-25 20:11:57 -04:00
|
|
|
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
|
2017-03-29 16:46:13 -04:00
|
|
|
gitlab_sign_in(user_exists("John Doe"))
|
2014-02-07 11:59:55 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
step 'I sign in as "Mary Jane"' do
|
2017-03-29 16:46:13 -04:00
|
|
|
gitlab_sign_in(user_exists("Mary Jane"))
|
2014-02-07 11:59:55 -05:00
|
|
|
end
|
|
|
|
|
2013-12-03 09:22:33 -05:00
|
|
|
step 'I should be redirected to sign in page' do
|
2015-06-12 00:44:13 -04:00
|
|
|
expect(current_path).to eq new_user_session_path
|
2013-12-03 09:22:33 -05:00
|
|
|
end
|
|
|
|
|
2014-06-26 03:49:14 -04:00
|
|
|
step "I logout" do
|
2017-03-29 16:46:13 -04:00
|
|
|
gitlab_sign_out
|
2014-06-26 03:49:14 -04:00
|
|
|
end
|
|
|
|
|
2015-06-20 00:18:24 -04:00
|
|
|
step "I logout directly" do
|
2017-03-29 16:46:13 -04:00
|
|
|
gitlab_sign_out
|
2015-06-20 00:18:24 -04:00
|
|
|
end
|
|
|
|
|
2012-09-27 16:23:11 -04:00
|
|
|
def current_user
|
2016-12-12 03:43:56 -05:00
|
|
|
@user || User.reorder(nil).first
|
2012-09-27 16:23:11 -04:00
|
|
|
end
|
2017-03-29 16:46:13 -04:00
|
|
|
|
|
|
|
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
|