summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/admin/users_controller_spec.rb15
-rw-r--r--spec/features/admin/admin_users_spec.rb21
2 files changed, 36 insertions, 0 deletions
diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb
index c40b2c2a583..7168db117d6 100644
--- a/spec/controllers/admin/users_controller_spec.rb
+++ b/spec/controllers/admin/users_controller_spec.rb
@@ -7,6 +7,21 @@ describe Admin::UsersController do
sign_in(admin)
end
+ describe 'POST login_as' do
+ let(:user) { create(:user) }
+
+ it 'logs admin as another user' do
+ expect(warden.authenticate(scope: :user)).not_to eq(user)
+ post :login_as, id: user.username
+ expect(warden.authenticate(scope: :user)).to eq(user)
+ end
+
+ it 'redirects user to homepage' do
+ post :login_as, id: user.username
+ expect(response).to redirect_to(root_path)
+ end
+ end
+
describe 'DELETE #user with projects' do
let(:user) { create(:user) }
let(:project) { create(:project, namespace: user.namespace) }
diff --git a/spec/features/admin/admin_users_spec.rb b/spec/features/admin/admin_users_spec.rb
index 86717761582..c2c7364f6c5 100644
--- a/spec/features/admin/admin_users_spec.rb
+++ b/spec/features/admin/admin_users_spec.rb
@@ -111,6 +111,27 @@ describe "Admin::Users", feature: true do
expect(page).to have_content(@user.name)
end
+ describe 'Login as another user' do
+ it 'should show login button for other users and check that it works' do
+ another_user = create(:user)
+
+ visit admin_user_path(another_user)
+
+ click_link 'Log in as this user'
+
+ expect(page).to have_content("Logged in as #{another_user.username}")
+
+ page.within '.sidebar-user .username' do
+ expect(page).to have_content(another_user.username)
+ end
+ end
+
+ it 'should not show login button for admin itself' do
+ visit admin_user_path(@user)
+ expect(page).not_to have_content('Log in as this user')
+ end
+ end
+
describe 'Two-factor Authentication status' do
it 'shows when enabled' do
@user.update_attribute(:two_factor_enabled, true)