Commit 8e8c0dbb authored by Serena Fang's avatar Serena Fang

Add specs for unban and ff disabled

Apply MR review suggestions

Add version history
parent f1b1e1df
...@@ -119,6 +119,8 @@ A deactivated user can also activate their account themselves by logging back in ...@@ -119,6 +119,8 @@ A deactivated user can also activate their account themselves by logging back in
## Ban and unban users ## Ban and unban users
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/327353) in GitLab 13.12.
GitLab administrators can ban users. GitLab administrators can ban users.
NOTE: NOTE:
......
...@@ -366,27 +366,55 @@ RSpec.describe Admin::UsersController do ...@@ -366,27 +366,55 @@ RSpec.describe Admin::UsersController do
end end
describe 'PUT ban/:id' do describe 'PUT ban/:id' do
it 'bans user' do context 'when ban_user_feature_flag is enabled' do
put :ban, params: { id: user.username } it 'bans user' do
put :ban, params: { id: user.username }
user.reload user.reload
expect(user.banned?).to be_truthy expect(user.banned?).to be_truthy
expect(flash[:notice]).to eq _('Successfully banned') 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 end
context 'when unsuccessful' do context 'when ban_user_feature_flag is not enabled' do
let(:user) { create(:user, :blocked) } before do
stub_feature_flags(ban_user_feature_flag: false)
end
it 'does not ban user' do it 'does not ban user, renders 404' do
put :ban, params: { id: user.username } put :ban, params: { id: user.username }
user.reload user.reload
expect(user.banned?).to be_falsey expect(user.banned?).to be_falsey
expect(flash[:alert]).to eq _('Error occurred. User was not banned') expect(response).to have_gitlab_http_status(:not_found)
end end
end 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 describe 'PUT unlock/:id' do
before do before do
request.env["HTTP_REFERER"] = "/" request.env["HTTP_REFERER"] = "/"
......
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