debian-mirror-gitlab/spec/support/helpers/admin_mode_helpers.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

22 lines
821 B
Ruby
Raw Normal View History

2019-12-21 20:55:43 +05:30
# frozen_string_literal: true
# Helper for enabling admin mode in tests
module AdminModeHelper
2020-01-01 13:55:28 +05:30
# Administrators are logged in by default in user mode and have to switch to admin
2019-12-21 20:55:43 +05:30
# mode for accessing any administrative functionality. This helper lets a user
# be in admin mode without requiring a second authentication step (provided
# the user is an admin)
2020-05-24 23:13:21 +05:30
#
# See also tag :enable_admin_mode in spec/spec_helper.rb for a spec-wide
# alternative
2019-12-21 20:55:43 +05:30
def enable_admin_mode!(user)
fake_user_mode = instance_double(Gitlab::Auth::CurrentUserMode)
2021-01-29 00:20:46 +05:30
allow(Gitlab::Auth::CurrentUserMode).to receive(:new).and_call_original
2019-12-21 20:55:43 +05:30
allow(Gitlab::Auth::CurrentUserMode).to receive(:new).with(user).and_return(fake_user_mode)
allow(fake_user_mode).to receive(:admin_mode?).and_return(user&.admin?)
end
end