diff options
Diffstat (limited to 'spec/controllers/admin/users_controller_spec.rb')
-rw-r--r-- | spec/controllers/admin/users_controller_spec.rb | 78 |
1 files changed, 76 insertions, 2 deletions
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"] = "/" |