summaryrefslogtreecommitdiff
path: root/spec/support/helpers/admin_mode_helpers.rb
blob: 36ed262f8ae66d781f2121f587e649238a20b3ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

# Helper for enabling admin mode in tests

module AdminModeHelper
  # Administrators are logged in by default in user mode and have to switch to admin
  # 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)
  #
  # See also tag :enable_admin_mode in spec/spec_helper.rb for a spec-wide
  # alternative
  def enable_admin_mode!(user)
    fake_user_mode = instance_double(Gitlab::Auth::CurrentUserMode)

    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