diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-05-19 18:44:42 +0300 |
commit | 4555e1b21c365ed8303ffb7a3325d773c9b8bf31 (patch) | |
tree | 5423a1c7516cffe36384133ade12572cf709398d /spec/controllers/admin | |
parent | e570267f2f6b326480d284e0164a6464ba4081bc (diff) |
Add latest changes from gitlab-org/gitlab@13-12-stable-eev13.12.0-rc42
Diffstat (limited to 'spec/controllers/admin')
6 files changed, 95 insertions, 14 deletions
diff --git a/spec/controllers/admin/cohorts_controller_spec.rb b/spec/controllers/admin/cohorts_controller_spec.rb index 77a9c8eb223..ba5406f25ab 100644 --- a/spec/controllers/admin/cohorts_controller_spec.rb +++ b/spec/controllers/admin/cohorts_controller_spec.rb @@ -12,6 +12,6 @@ RSpec.describe Admin::CohortsController do it 'redirects to Overview->Users' do get :index - expect(response).to redirect_to(admin_users_path(tab: 'cohorts')) + expect(response).to redirect_to(cohorts_admin_users_path) end end diff --git a/spec/controllers/admin/dev_ops_report_controller_spec.rb b/spec/controllers/admin/dev_ops_report_controller_spec.rb index 142db175a15..49e6c0f69bd 100644 --- a/spec/controllers/admin/dev_ops_report_controller_spec.rb +++ b/spec/controllers/admin/dev_ops_report_controller_spec.rb @@ -9,12 +9,6 @@ RSpec.describe Admin::DevOpsReportController do end end - describe 'should_track_devops_score?' do - it 'is always true' do - expect(controller.should_track_devops_score?).to be_truthy - end - end - describe 'GET #show' do context 'as admin' do let(:user) { create(:admin) } @@ -31,6 +25,8 @@ RSpec.describe Admin::DevOpsReportController do it_behaves_like 'tracking unique visits', :show do let(:target_id) { 'i_analytics_dev_ops_score' } + + let(:request_params) { { tab: 'devops-score' } } end end end diff --git a/spec/controllers/admin/groups_controller_spec.rb b/spec/controllers/admin/groups_controller_spec.rb index 8441a52b454..8e31ef12adf 100644 --- a/spec/controllers/admin/groups_controller_spec.rb +++ b/spec/controllers/admin/groups_controller_spec.rb @@ -55,7 +55,7 @@ RSpec.describe Admin::GroupsController do access_level: Gitlab::Access::GUEST } - expect(response).to set_flash.to 'Users were successfully added.' + expect(controller).to set_flash.to 'Users were successfully added.' expect(response).to redirect_to(admin_group_path(group)) expect(group.users).to include group_user end @@ -67,7 +67,7 @@ RSpec.describe Admin::GroupsController do access_level: Gitlab::Access::GUEST } - expect(response).to set_flash.to 'Users were successfully added.' + expect(controller).to set_flash.to 'Users were successfully added.' expect(response).to redirect_to(admin_group_path(group)) end @@ -78,7 +78,7 @@ RSpec.describe Admin::GroupsController do access_level: Gitlab::Access::GUEST } - expect(response).to set_flash.to 'No users specified.' + expect(controller).to set_flash.to 'No users specified.' expect(response).to redirect_to(admin_group_path(group)) expect(group.users).not_to include group_user end diff --git a/spec/controllers/admin/integrations_controller_spec.rb b/spec/controllers/admin/integrations_controller_spec.rb index e14619a9916..971f2f121aa 100644 --- a/spec/controllers/admin/integrations_controller_spec.rb +++ b/spec/controllers/admin/integrations_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Admin::IntegrationsController do end describe '#edit' do - Service.available_services_names.each do |integration_name| + Integration.available_services_names.each do |integration_name| context "#{integration_name}" do it 'successfully displays the template' do get :edit, params: { id: integration_name } @@ -27,7 +27,7 @@ RSpec.describe Admin::IntegrationsController do end it 'returns 404' do - get :edit, params: { id: Service.available_services_names.sample } + get :edit, params: { id: Integration.available_services_names.sample } expect(response).to have_gitlab_http_status(:not_found) end diff --git a/spec/controllers/admin/runners_controller_spec.rb b/spec/controllers/admin/runners_controller_spec.rb index 45ea8949bf2..3984784f045 100644 --- a/spec/controllers/admin/runners_controller_spec.rb +++ b/spec/controllers/admin/runners_controller_spec.rb @@ -34,6 +34,17 @@ RSpec.describe Admin::RunnersController do expect(response.body).to have_content('tag1') expect(response.body).to have_content('tag2') end + + it 'paginates runners' do + stub_const("Admin::RunnersController::NUMBER_OF_RUNNERS_PER_PAGE", 1) + + create(:ci_runner) + + get :index + + expect(response).to have_gitlab_http_status(:ok) + expect(assigns(:runners).count).to be(1) + end end describe '#show' do diff --git a/spec/controllers/admin/users_controller_spec.rb b/spec/controllers/admin/users_controller_spec.rb index 6faec315eb6..722c9c322cc 100644 --- a/spec/controllers/admin/users_controller_spec.rb +++ b/spec/controllers/admin/users_controller_spec.rb @@ -30,9 +30,33 @@ RSpec.describe Admin::UsersController do expect(assigns(:users).first.association(:authorized_projects)).to be_loaded end - it_behaves_like 'tracking unique visits', :index do + context 'pagination' do + context 'when number of users is over the pagination limit' do + before do + stub_const('Admin::UsersController::PAGINATION_WITH_COUNT_LIMIT', 5) + allow(Gitlab::Database::Count).to receive(:approximate_counts).with([User]).and_return({ User => 6 }) + end + + it 'marks the relation for pagination without counts' do + get :index + + expect(assigns(:users)).to be_a(Kaminari::PaginatableWithoutCount) + end + end + + context 'when number of users is below the pagination limit' do + it 'marks the relation for pagination with counts' do + get :index + + expect(assigns(:users)).not_to be_a(Kaminari::PaginatableWithoutCount) + end + end + end + end + + describe 'GET #cohorts' do + it_behaves_like 'tracking unique visits', :cohorts do let(:target_id) { 'i_analytics_cohorts' } - let(:request_params) { { tab: 'cohorts' } } end end @@ -341,6 +365,56 @@ RSpec.describe Admin::UsersController do end end + describe 'PUT ban/:id' do + context 'when ban_user_feature_flag is enabled' do + it 'bans user' do + put :ban, params: { id: user.username } + + user.reload + expect(user.banned?).to be_truthy + expect(flash[:notice]).to eq _('Successfully banned') + end + + context 'when unsuccessful' do + let(:user) { create(:user, :blocked) } + + it 'does not ban user' do + put :ban, params: { id: user.username } + + user.reload + expect(user.banned?).to be_falsey + expect(flash[:alert]).to eq _('Error occurred. User was not banned') + end + end + end + + context 'when ban_user_feature_flag is not enabled' do + before do + stub_feature_flags(ban_user_feature_flag: false) + end + + it 'does not ban user, renders 404' do + put :ban, params: { id: user.username } + + user.reload + expect(user.banned?).to be_falsey + expect(response).to have_gitlab_http_status(:not_found) + end + end + end + + describe 'PUT unban/:id' do + let(:banned_user) { create(:user, :banned) } + + it 'unbans user' do + put :unban, params: { id: banned_user.username } + + banned_user.reload + expect(banned_user.banned?).to be_falsey + expect(flash[:notice]).to eq _('Successfully unbanned') + end + end + describe 'PUT unlock/:id' do before do request.env["HTTP_REFERER"] = "/" |