Commit 457e1881 authored by Diego Louzán's avatar Diego Louzán

Disable auto admin mode on requests and views specs

Continue ongoing migration of all specs to disable auto admin mode
for requests and views.
parent 11277843
---
title: Disable auto admin mode on requests and views specs
merge_request: 48700
author: Diego Louzán
type: other
......@@ -3,6 +3,8 @@
require 'spec_helper'
RSpec.describe 'view audit events' do
include AdminModeHelper
describe 'GET /audit_events' do
let_it_be(:admin) { create(:admin) }
let_it_be(:audit_event) { create(:user_audit_event) }
......@@ -13,23 +15,37 @@ RSpec.describe 'view audit events' do
login_as(admin)
end
it 'returns 200 response' do
send_request
context 'when admin mode is enabled' do
before do
enable_admin_mode!(admin)
end
expect(response).to have_gitlab_http_status(:ok)
end
it 'returns 200 response' do
send_request
expect(response).to have_gitlab_http_status(:ok)
end
it 'avoids N+1 DB queries', :request_store do
# warm up cache so these initial queries would not leak in our QueryRecorder
send_request
it 'avoids N+1 DB queries', :request_store do
# warm up cache so these initial queries would not leak in our QueryRecorder
send_request
control = ActiveRecord::QueryRecorder.new(skip_cached: false) { send_request }
control = ActiveRecord::QueryRecorder.new(skip_cached: false) { send_request }
create_list(:user_audit_event, 2)
create_list(:user_audit_event, 2)
expect do
send_request
end.not_to exceed_all_query_limit(control)
end
end
expect do
context 'when admin mode is disabled' do
it 'redirects to admin mode enable' do
send_request
end.not_to exceed_all_query_limit(control)
expect(response).to redirect_to(new_admin_session_path)
end
end
def send_request
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Admin::AbuseReportsController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
include AdminModeHelper
let(:admin) { create(:admin) }
let!(:abuse_report) { create(:abuse_report) }
......@@ -18,6 +19,7 @@ RSpec.describe Admin::AbuseReportsController, '(JavaScript fixtures)', type: :co
before do
sign_in(admin)
enable_admin_mode!(admin)
end
it 'abuse_reports/abuse_reports_list.html' do
......
......@@ -5,12 +5,14 @@ require 'spec_helper'
RSpec.describe Admin::UsersController, '(JavaScript fixtures)', type: :controller do
include StubENV
include JavaScriptFixturesHelpers
include AdminModeHelper
let(:admin) { create(:admin) }
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
sign_in(admin)
enable_admin_mode!(admin)
end
render_views
......
......@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe Admin::ApplicationSettingsController, '(JavaScript fixtures)', type: :controller do
include StubENV
include JavaScriptFixturesHelpers
include AdminModeHelper
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
......@@ -13,6 +14,7 @@ RSpec.describe Admin::ApplicationSettingsController, '(JavaScript fixtures)', ty
before do
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
sign_in(admin)
enable_admin_mode!(admin)
end
render_views
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Projects::AutocompleteSourcesController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let_it_be(:admin) { create(:admin) }
let_it_be(:user) { create(:user) }
let_it_be(:group) { create(:group, name: 'frontend-fixtures') }
let_it_be(:project) { create(:project, namespace: group, path: 'autocomplete-sources-project') }
let_it_be(:issue) { create(:issue, project: project) }
......@@ -15,7 +15,8 @@ RSpec.describe Projects::AutocompleteSourcesController, '(JavaScript fixtures)',
end
before do
sign_in(admin)
group.add_owner(user)
sign_in(user)
end
it 'autocomplete_sources/labels.json' do
......
......@@ -5,9 +5,9 @@ require 'spec_helper'
RSpec.describe Projects::BlobController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :repository, namespace: namespace, path: 'branches-project') }
let(:user) { project.owner }
render_views
......@@ -16,7 +16,7 @@ RSpec.describe Projects::BlobController, '(JavaScript fixtures)', type: :control
end
before do
sign_in(admin)
sign_in(user)
allow(SecureRandom).to receive(:hex).and_return('securerandomhex:thereisnospoon')
end
......
......@@ -5,9 +5,9 @@ require 'spec_helper'
RSpec.describe 'Branches (JavaScript fixtures)' do
include JavaScriptFixturesHelpers
let_it_be(:admin) { create(:admin) }
let_it_be(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let_it_be(:project) { create(:project, :repository, namespace: namespace, path: 'branches-project') }
let_it_be(:user) { project.owner }
before(:all) do
clean_frontend_fixtures('branches/')
......@@ -22,7 +22,7 @@ RSpec.describe 'Branches (JavaScript fixtures)' do
render_views
before do
sign_in(admin)
sign_in(user)
end
it 'branches/new_branch.html' do
......@@ -44,7 +44,7 @@ RSpec.describe 'Branches (JavaScript fixtures)' do
# - "master": default, protected
# - "markdown": non-default, protected
# - "many_files": non-default, not protected
get api("/projects/#{project.id}/repository/branches?search=ma", admin)
get api("/projects/#{project.id}/repository/branches?search=ma", user)
expect(response).to be_successful
end
......
......@@ -5,10 +5,10 @@ require 'spec_helper'
RSpec.describe Projects::ClustersController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :repository, namespace: namespace) }
let(:cluster) { create(:cluster, :provided_by_gcp, projects: [project]) }
let(:user) { project.owner }
render_views
......@@ -17,7 +17,7 @@ RSpec.describe Projects::ClustersController, '(JavaScript fixtures)', type: :con
end
before do
sign_in(admin)
sign_in(user)
end
after do
......
......@@ -6,14 +6,12 @@ RSpec.describe 'Commit (JavaScript fixtures)' do
include JavaScriptFixturesHelpers
let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:user) { project.owner }
let_it_be(:commit) { project.commit("master") }
before(:all) do
clean_frontend_fixtures('commit/')
clean_frontend_fixtures('api/commits/')
project.add_maintainer(user)
end
before do
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe Projects::DeployKeysController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
include AdminModeHelper
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
......@@ -17,7 +18,10 @@ RSpec.describe Projects::DeployKeysController, '(JavaScript fixtures)', type: :c
end
before do
# Using an admin for these fixtures because they are used for verifying a frontend
# component that would normally get its data from `Admin::DeployKeysController`
sign_in(admin)
enable_admin_mode!(admin)
end
after do
......
......@@ -6,8 +6,8 @@ RSpec.describe 'Freeze Periods (JavaScript fixtures)' do
include JavaScriptFixturesHelpers
include TimeZoneHelper
let_it_be(:admin) { create(:admin) }
let_it_be(:project) { create(:project, :repository, path: 'freeze-periods-project') }
let_it_be(:user) { project.owner }
before(:all) do
clean_frontend_fixtures('api/freeze-periods/')
......@@ -34,7 +34,7 @@ RSpec.describe 'Freeze Periods (JavaScript fixtures)' do
create(:ci_freeze_period, project: project, freeze_start: '0 12 * * 1-5', freeze_end: '0 1 5 * *', cron_timezone: 'Etc/UTC')
create(:ci_freeze_period, project: project, freeze_start: '0 12 * * 1-5', freeze_end: '0 16 * * 6', cron_timezone: 'Europe/Berlin')
get api("/projects/#{project.id}/freeze_periods", admin)
get api("/projects/#{project.id}/freeze_periods", user)
expect(response).to be_successful
end
......
......@@ -5,20 +5,20 @@ require 'spec_helper'
RSpec.describe 'Groups (JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:user) { create(:user) }
let(:group) { create(:group, name: 'frontend-fixtures-group', runners_token: 'runnerstoken:intabulasreferre')}
render_views
before(:all) do
clean_frontend_fixtures('groups/')
end
before do
group.add_maintainer(admin)
sign_in(admin)
group.add_owner(user)
sign_in(user)
end
render_views
describe GroupsController, '(JavaScript fixtures)', type: :controller do
it 'groups/edit.html' do
get :edit, params: { id: group }
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe Projects::IssuesController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin, feed_token: 'feedtoken:coldfeed') }
let(:user) { create(:user, feed_token: 'feedtoken:coldfeed') }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project_empty_repo, namespace: namespace, path: 'issues-project') }
......@@ -16,7 +16,8 @@ RSpec.describe Projects::IssuesController, '(JavaScript fixtures)', type: :contr
end
before do
sign_in(admin)
project.add_maintainer(user)
sign_in(user)
end
after do
......
......@@ -5,9 +5,9 @@ require 'spec_helper'
RSpec.describe Projects::JobsController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :repository, namespace: namespace, path: 'builds-project') }
let(:user) { project.owner }
let(:pipeline) { create(:ci_empty_pipeline, project: project, sha: project.commit.id) }
let!(:build_with_artifacts) { create(:ci_build, :success, :artifacts, :trace_artifact, pipeline: pipeline, stage: 'test', artifacts_expire_at: Time.now + 18.months) }
let!(:failed_build) { create(:ci_build, :failed, pipeline: pipeline, stage: 'build') }
......@@ -26,7 +26,7 @@ RSpec.describe Projects::JobsController, '(JavaScript fixtures)', type: :control
end
before do
sign_in(admin)
sign_in(user)
end
after do
......
......@@ -5,7 +5,7 @@ require 'spec_helper'
RSpec.describe 'Labels (JavaScript fixtures)' do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:user) { create(:user) }
let(:group) { create(:group, name: 'frontend-fixtures-group' )}
let(:project) { create(:project_empty_repo, namespace: group, path: 'labels-project') }
......@@ -29,8 +29,6 @@ RSpec.describe 'Labels (JavaScript fixtures)' do
include JavaScriptFixturesHelpers
include ApiHelpers
let(:user) { create(:user) }
before do
group.add_owner(user)
end
......@@ -46,7 +44,8 @@ RSpec.describe 'Labels (JavaScript fixtures)' do
render_views
before do
sign_in(admin)
group.add_owner(user)
sign_in(user)
end
it 'labels/project_labels.json' do
......
......@@ -5,9 +5,9 @@ require 'spec_helper'
RSpec.describe Projects::MergeRequestsController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :repository, namespace: namespace, path: 'merge-requests-project') }
let(:user) { project.owner }
# rubocop: disable Layout/TrailingWhitespace
let(:description) do
......@@ -55,7 +55,7 @@ RSpec.describe Projects::MergeRequestsController, '(JavaScript fixtures)', type:
end
before do
sign_in(admin)
sign_in(user)
allow(Discussion).to receive(:build_discussion_id).and_return(['discussionid:ceterumcenseo'])
end
......@@ -64,7 +64,7 @@ RSpec.describe Projects::MergeRequestsController, '(JavaScript fixtures)', type:
end
it 'merge_requests/merge_request_of_current_user.html' do
merge_request.update(author: admin)
merge_request.update(author: user)
render_merge_request(merge_request)
end
......@@ -76,19 +76,19 @@ RSpec.describe Projects::MergeRequestsController, '(JavaScript fixtures)', type:
end
it 'merge_requests/diff_comment.html' do
create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
create(:note_on_merge_request, author: admin, project: project, noteable: merge_request)
create(:diff_note_on_merge_request, project: project, author: user, position: position, noteable: merge_request)
create(:note_on_merge_request, author: user, project: project, noteable: merge_request)
render_merge_request(merge_request)
end
it 'merge_requests/diff_discussion.json' do
create(:diff_note_on_merge_request, project: project, author: admin, position: position, noteable: merge_request)
create(:diff_note_on_merge_request, project: project, author: user, position: position, noteable: merge_request)
render_discussions_json(merge_request)
end
it 'merge_requests/resolved_diff_discussion.json' do
note = create(:discussion_note_on_merge_request, :resolved, project: project, author: admin, position: position, noteable: merge_request)
create(:system_note, project: project, author: admin, noteable: merge_request, discussion_id: note.discussion.id)
note = create(:discussion_note_on_merge_request, :resolved, project: project, author: user, position: position, noteable: merge_request)
create(:system_note, project: project, author: user, noteable: merge_request, discussion_id: note.discussion.id)
render_discussions_json(merge_request)
end
......@@ -111,7 +111,7 @@ RSpec.describe Projects::MergeRequestsController, '(JavaScript fixtures)', type:
context 'with mentions' do
let(:group) { create(:group) }
let(:description) { "@#{group.full_path} @all @#{admin.username}" }
let(:description) { "@#{group.full_path} @all @#{user.username}" }
it 'merge_requests/merge_request_with_mentions.html' do
render_merge_request(merge_request)
......
......@@ -5,9 +5,9 @@ require 'spec_helper'
RSpec.describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :repository, namespace: namespace, path: 'merge-requests-project') }
let(:user) { project.owner }
let(:merge_request) { create(:merge_request, :with_diffs, source_project: project, target_project: project, description: '- [ ] Task List Item') }
let(:path) { "files/ruby/popen.rb" }
let(:position) do
......@@ -25,7 +25,7 @@ RSpec.describe Projects::MergeRequests::DiffsController, '(JavaScript fixtures)'
end
before do
sign_in(admin)
sign_in(user)
end
after do
......
......@@ -5,11 +5,11 @@ require 'spec_helper'
RSpec.describe Projects::PipelineSchedulesController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :public, :repository) }
let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: admin) }
let!(:pipeline_schedule_populated) { create(:ci_pipeline_schedule, project: project, owner: admin) }
let(:user) { project.owner }
let!(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: user) }
let!(:pipeline_schedule_populated) { create(:ci_pipeline_schedule, project: project, owner: user) }
let!(:pipeline_schedule_variable1) { create(:ci_pipeline_schedule_variable, key: 'foo', value: 'foovalue', pipeline_schedule: pipeline_schedule_populated) }
let!(:pipeline_schedule_variable2) { create(:ci_pipeline_schedule_variable, key: 'bar', value: 'barvalue', pipeline_schedule: pipeline_schedule_populated) }
......@@ -20,7 +20,7 @@ RSpec.describe Projects::PipelineSchedulesController, '(JavaScript fixtures)', t
end
before do
sign_in(admin)
sign_in(user)
end
it 'pipeline_schedules/edit.html' do
......
......@@ -5,7 +5,6 @@ require 'spec_helper'
RSpec.describe Projects::PipelinesController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :repository, namespace: namespace, path: 'pipelines-project') }
let(:commit) { create(:commit, project: project) }
......@@ -22,7 +21,7 @@ RSpec.describe Projects::PipelinesController, '(JavaScript fixtures)', type: :co
end
before do
sign_in(admin)
sign_in(user)
end
it 'pipelines/pipelines.json' do
......
......@@ -7,11 +7,11 @@ RSpec.describe 'Projects (JavaScript fixtures)', type: :controller do
runners_token = 'runnerstoken:intabulasreferre'
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, namespace: namespace, path: 'builds-project', runners_token: runners_token) }
let(:project_with_repo) { create(:project, :repository, description: 'Code and stuff') }
let(:project_variable_populated) { create(:project, namespace: namespace, path: 'builds-project2', runners_token: runners_token) }
let(:user) { project.owner }
render_views
......@@ -20,8 +20,8 @@ RSpec.describe 'Projects (JavaScript fixtures)', type: :controller do
end
before do
project.add_maintainer(admin)
sign_in(admin)
project_with_repo.add_maintainer(user)
sign_in(user)
allow(SecureRandom).to receive(:hex).and_return('securerandomhex:thereisnospoon')
end
......
......@@ -5,10 +5,10 @@ require 'spec_helper'
RSpec.describe Projects::ServicesController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project_empty_repo, namespace: namespace, path: 'services-project') }
let!(:service) { create(:prometheus_service, project: project) }
let(:user) { project.owner }
render_views
......@@ -17,7 +17,7 @@ RSpec.describe Projects::ServicesController, '(JavaScript fixtures)', type: :con
end
before do
sign_in(admin)
sign_in(user)
end
after do
......
......@@ -7,7 +7,7 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
render_views
let_it_be(:user) { create(:admin) }
let_it_be(:user) { create(:user) }
before(:all) do
clean_frontend_fixtures('search/')
......@@ -66,6 +66,10 @@ RSpec.describe SearchController, '(JavaScript fixtures)', type: :controller do
offset: 0)
end
before do
project.add_developer(user)
end
it 'search/blob_search_result.html' do
allow_next_instance_of(SearchServicePresenter) do |search_service|
allow(search_service).to receive(:search_objects).and_return(blobs)
......
......@@ -5,10 +5,10 @@ require 'spec_helper'
RSpec.describe Projects::ServicesController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project_empty_repo, namespace: namespace, path: 'services-project') }
let!(:service) { create(:custom_issue_tracker_service, project: project) }
let(:user) { project.owner }
render_views
......@@ -17,7 +17,7 @@ RSpec.describe Projects::ServicesController, '(JavaScript fixtures)', type: :con
end
before do
sign_in(admin)
sign_in(user)
end
after do
......
......@@ -5,10 +5,10 @@ require 'spec_helper'
RSpec.describe SnippetsController, '(JavaScript fixtures)', type: :controller do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project, :repository, namespace: namespace, path: 'branches-project') }
let(:snippet) { create(:personal_snippet, :public, title: 'snippet.md', content: '# snippet', file_name: 'snippet.md', author: admin) }
let(:user) { project.owner }
let(:snippet) { create(:personal_snippet, :public, title: 'snippet.md', content: '# snippet', file_name: 'snippet.md', author: user) }
render_views
......@@ -17,7 +17,7 @@ RSpec.describe SnippetsController, '(JavaScript fixtures)', type: :controller do
end
before do
sign_in(admin)
sign_in(user)
allow(Discussion).to receive(:build_discussion_id).and_return(['discussionid:ceterumcenseo'])
end
......@@ -26,7 +26,7 @@ RSpec.describe SnippetsController, '(JavaScript fixtures)', type: :controller do
end
it 'snippets/show.html' do
create(:discussion_note_on_project_snippet, noteable: snippet, project: project, author: admin, note: '- [ ] Task List Item')
create(:discussion_note_on_project_snippet, noteable: snippet, project: project, author: user, note: '- [ ] Task List Item')
get(:show, params: { id: snippet.to_param })
......
......@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec.describe 'Tags (JavaScript fixtures)' do
include JavaScriptFixturesHelpers
let_it_be(:admin) { create(:admin) }
let_it_be(:project) { create(:project, :repository, path: 'tags-project') }
let_it_be(:user) { project.owner }
before(:all) do
clean_frontend_fixtures('api/tags/')
......@@ -20,7 +20,7 @@ RSpec.describe 'Tags (JavaScript fixtures)' do
include ApiHelpers
it 'api/tags/tags.json' do
get api("/projects/#{project.id}/repository/tags", admin)
get api("/projects/#{project.id}/repository/tags", user)
expect(response).to be_successful
end
......
......@@ -5,13 +5,13 @@ require 'spec_helper'
RSpec.describe 'Todos (JavaScript fixtures)' do
include JavaScriptFixturesHelpers
let(:admin) { create(:admin) }
let(:namespace) { create(:namespace, name: 'frontend-fixtures' )}
let(:project) { create(:project_empty_repo, namespace: namespace, path: 'todos-project') }
let(:user) { project.owner }
let(:issue_1) { create(:issue, title: 'issue_1', project: project) }
let!(:todo_1) { create(:todo, user: admin, project: project, target: issue_1, created_at: 5.hours.ago) }
let!(:todo_1) { create(:todo, user: user, project: project, target: issue_1, created_at: 5.hours.ago) }
let(:issue_2) { create(:issue, title: 'issue_2', project: project) }
let!(:todo_2) { create(:todo, :done, user: admin, project: project, target: issue_2, created_at: 50.hours.ago) }
let!(:todo_2) { create(:todo, :done, user: user, project: project, target: issue_2, created_at: 50.hours.ago) }
before(:all) do
clean_frontend_fixtures('todos/')
......@@ -25,7 +25,7 @@ RSpec.describe 'Todos (JavaScript fixtures)' do
render_views
before do
sign_in(admin)
sign_in(user)
end
it 'todos/todos.html' do
......@@ -39,7 +39,7 @@ RSpec.describe 'Todos (JavaScript fixtures)' do
render_views
before do
sign_in(admin)
sign_in(user)
end
it 'todos/todos.json' do
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe NavHelper, :do_not_mock_admin_mode do
RSpec.describe NavHelper do
describe '#header_links' do
include_context 'custom session'
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe API::APIGuard::AdminModeMiddleware, :do_not_mock_admin_mode, :request_store do
RSpec.describe API::APIGuard::AdminModeMiddleware, :request_store do
let(:user) { create(:admin) }
it 'is loaded' do
......
......@@ -4,7 +4,7 @@ require 'spec_helper'
# Based on spec/requests/api/groups_spec.rb
# Should follow closely in order to ensure all situations are covered
RSpec.describe 'getting group information', :do_not_mock_admin_mode do
RSpec.describe 'getting group information' do
include GraphqlHelpers
include UploadHelpers
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe 'Mark snippet as spam', :do_not_mock_admin_mode do
RSpec.describe 'Mark snippet as spam' do
include GraphqlHelpers
let_it_be(:admin) { create(:admin) }
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe API::Users, :do_not_mock_admin_mode do
RSpec.describe API::Users do
let_it_be(:admin) { create(:admin) }
let_it_be(:user, reload: true) { create(:user, username: 'user.with.dot') }
let_it_be(:key) { create(:key, user: user) }
......
......@@ -795,12 +795,24 @@ RSpec.describe 'Git HTTP requests' do
context 'administrator' do
let(:user) { create(:admin) }
it_behaves_like 'can download code only'
context 'when admin mode is enabled', :enable_admin_mode do
it_behaves_like 'can download code only'
it 'downloads from other project get status 403' do
clone_get "#{other_project.full_path}.git", user: 'gitlab-ci-token', password: build.token
it 'downloads from other project get status 403' do
clone_get "#{other_project.full_path}.git", user: 'gitlab-ci-token', password: build.token
expect(response).to have_gitlab_http_status(:forbidden)
expect(response).to have_gitlab_http_status(:forbidden)
end
end
context 'when admin mode is disabled' do
it_behaves_like 'can download code only'
it 'downloads from other project get status 404' do
clone_get "#{other_project.full_path}.git", user: 'gitlab-ci-token', password: build.token
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
......
......@@ -195,7 +195,7 @@ RSpec.describe 'Git LFS API and storage' do
end
end
context 'administrator' do
context 'administrator', :enable_admin_mode do
let(:user) { create(:admin) }
let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) }
......@@ -453,7 +453,7 @@ RSpec.describe 'Git LFS API and storage' do
end
end
context 'administrator' do
context 'administrator', :enable_admin_mode do
let(:user) { create(:admin) }
let(:build) { create(:ci_build, :running, pipeline: pipeline, user: user) }
......
......@@ -12,7 +12,7 @@ RSpec.describe 'Self-Monitoring project requests' do
it_behaves_like 'not accessible to non-admin users'
context 'with admin user' do
context 'with admin user', :enable_admin_mode do
before do
login_as(admin)
end
......@@ -36,7 +36,7 @@ RSpec.describe 'Self-Monitoring project requests' do
it_behaves_like 'not accessible to non-admin users'
context 'with admin user' do
context 'with admin user', :enable_admin_mode do
before do
login_as(admin)
end
......@@ -116,7 +116,7 @@ RSpec.describe 'Self-Monitoring project requests' do
it_behaves_like 'not accessible to non-admin users'
context 'with admin user' do
context 'with admin user', :enable_admin_mode do
before do
login_as(admin)
end
......@@ -140,7 +140,7 @@ RSpec.describe 'Self-Monitoring project requests' do
it_behaves_like 'not accessible to non-admin users'
context 'with admin user' do
context 'with admin user', :enable_admin_mode do
before do
login_as(admin)
end
......
......@@ -286,19 +286,13 @@ RSpec.configure do |config|
./ee/spec/elastic_integration
./ee/spec/finders
./ee/spec/lib
./ee/spec/requests/admin
./ee/spec/serializers
./ee/spec/support/shared_examples/finders/geo
./ee/spec/support/shared_examples/graphql/geo
./spec/finders
./spec/frontend
./spec/helpers
./spec/lib
./spec/requests
./spec/serializers
./spec/support/shared_examples/requests
./spec/support/shared_examples/lib/gitlab
./spec/views
./spec/workers
)
......
......@@ -20,6 +20,18 @@ RSpec.shared_examples 'not accessible to non-admin users' do
expect(response).to have_gitlab_http_status(:not_found)
end
end
context 'with authenticated admin user without admin mode' do
before do
login_as(create(:admin))
end
it 'redirects to enable admin mode' do
subject
expect(response).to redirect_to(new_admin_session_path)
end
end
end
# Requires subject and worker_class and status_api to be defined
......
......@@ -16,10 +16,21 @@ RSpec.describe "projects/artifacts/_artifact.html.haml" do
context 'with admin' do
let(:user) { build(:admin) }
it 'has a delete button' do
render_partial
context 'when admin mode is enabled', :enable_admin_mode do
it 'has a delete button' do
render_partial
expect(rendered).to have_link('Delete artifacts', href: project_artifact_path(project, project.job_artifacts.first))
expect(rendered).to have_link('Delete artifacts', href: project_artifact_path(project, project.job_artifacts.first))
end
end
context 'when admin mode is disabled' do
it 'has no delete button' do
project.add_reporter(user)
render_partial
expect(rendered).not_to have_link('Delete artifacts')
end
end
end
......
......@@ -54,11 +54,22 @@ RSpec.describe 'search/_results' do
let(:scope) { search_scope }
let(:search_objects) { Gitlab::ProjectSearchResults.new(user, '*', project: project).objects(scope) }
it 'renders the click text event tracking attributes' do
render
context 'when admin mode is enabled', :enable_admin_mode do
it 'renders the click text event tracking attributes' do
render
expect(rendered).to have_selector('[data-track-event=click_text]')
expect(rendered).to have_selector('[data-track-property=search_result]')
end
end
context 'when admin mode is disabled' do
it 'does not render the click text event tracking attributes' do
render
expect(rendered).to have_selector('[data-track-event=click_text]')
expect(rendered).to have_selector('[data-track-property=search_result]')
expect(rendered).not_to have_selector('[data-track-event=click_text]')
expect(rendered).not_to have_selector('[data-track-property=search_result]')
end
end
it 'does render the sidebar' do
......@@ -74,11 +85,22 @@ RSpec.describe 'search/_results' do
let(:scope) { search_scope }
let(:search_objects) { Gitlab::ProjectSearchResults.new(user, '*', project: project).objects(scope) }
it 'renders the click text event tracking attributes' do
render
context 'when admin mode is enabled', :enable_admin_mode do
it 'renders the click text event tracking attributes' do
render
expect(rendered).to have_selector('[data-track-event=click_text]')
expect(rendered).to have_selector('[data-track-property=search_result]')
end
end
context 'when admin mode is disabled' do
it 'does not render the click text event tracking attributes' do
render
expect(rendered).to have_selector('[data-track-event=click_text]')
expect(rendered).to have_selector('[data-track-property=search_result]')
expect(rendered).not_to have_selector('[data-track-event=click_text]')
expect(rendered).not_to have_selector('[data-track-property=search_result]')
end
end
it 'does not render the sidebar' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment