Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
04a35642
Commit
04a35642
authored
Oct 02, 2020
by
Serena Fang
Committed by
Peter Leitzen
Oct 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY api/users_spec activation specs
parent
dd456683
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
10 deletions
+20
-10
spec/requests/api/users_spec.rb
spec/requests/api/users_spec.rb
+20
-10
No files found.
spec/requests/api/users_spec.rb
View file @
04a35642
...
...
@@ -2291,23 +2291,31 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
end
describe
'POST /users/:id/activate'
do
subject
(
:activate
)
{
post
api
(
"/users/
#{
user_id
}
/activate"
,
api_user
)
}
let
(
:user_id
)
{
user
.
id
}
context
'performed by a non-admin user'
do
let
(
:api_user
)
{
user
}
it
'is not authorized to perform the action'
do
post
api
(
"/users/
#{
user
.
id
}
/activate"
,
user
)
activate
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
context
'performed by an admin user'
do
let
(
:api_user
)
{
admin
}
context
'for a deactivated user'
do
before
do
user
.
deactivate
post
api
(
"/users/
#{
user
.
id
}
/activate"
,
admin
)
end
it
'activates a deactivated user'
do
activate
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
...
...
@@ -2316,11 +2324,11 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
context
'for an active user'
do
before
do
user
.
activate
post
api
(
"/users/
#{
user
.
id
}
/activate"
,
admin
)
end
it
'returns 201'
do
activate
expect
(
response
).
to
have_gitlab_http_status
(
:created
)
expect
(
user
.
reload
.
state
).
to
eq
(
'active'
)
end
...
...
@@ -2329,11 +2337,11 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
context
'for a blocked user'
do
before
do
user
.
block
post
api
(
"/users/
#{
user
.
id
}
/activate"
,
admin
)
end
it
'returns 403'
do
activate
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
expect
(
json_response
[
'message'
]).
to
eq
(
'403 Forbidden - A blocked user must be unblocked to be activated'
)
expect
(
user
.
reload
.
state
).
to
eq
(
'blocked'
)
...
...
@@ -2343,11 +2351,11 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
context
'for a ldap blocked user'
do
before
do
user
.
ldap_block
post
api
(
"/users/
#{
user
.
id
}
/activate"
,
admin
)
end
it
'returns 403'
do
activate
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
expect
(
json_response
[
'message'
]).
to
eq
(
'403 Forbidden - A blocked user must be unblocked to be activated'
)
expect
(
user
.
reload
.
state
).
to
eq
(
'ldap_blocked'
)
...
...
@@ -2355,8 +2363,10 @@ RSpec.describe API::Users, :do_not_mock_admin_mode do
end
context
'for a user that does not exist'
do
let
(
:user_id
)
{
0
}
before
do
post
api
(
"/users/0/activate"
,
admin
)
activate
end
it_behaves_like
'404'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment