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
ed364588
Commit
ed364588
authored
Feb 04, 2020
by
Rajendra Kadam
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Separate patch and get tests in different describe blocks in specs
parent
b118e4dd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
103 additions
and
69 deletions
+103
-69
lib/api/error_tracking.rb
lib/api/error_tracking.rb
+1
-1
spec/requests/api/error_tracking_spec.rb
spec/requests/api/error_tracking_spec.rb
+102
-68
No files found.
lib/api/error_tracking.rb
View file @
ed364588
...
@@ -24,7 +24,7 @@ module API
...
@@ -24,7 +24,7 @@ module API
present
setting
,
with:
Entities
::
ErrorTracking
::
ProjectSetting
present
setting
,
with:
Entities
::
ErrorTracking
::
ProjectSetting
end
end
desc
'Enable
/D
isable error tracking settings for the project'
do
desc
'Enable
or d
isable error tracking settings for the project'
do
detail
'This feature was introduced in GitLab 12.8.'
detail
'This feature was introduced in GitLab 12.8.'
success
Entities
::
ErrorTracking
::
ProjectSetting
success
Entities
::
ErrorTracking
::
ProjectSetting
end
end
...
...
spec/requests/api/error_tracking_spec.rb
View file @
ed364588
...
@@ -3,76 +3,126 @@
...
@@ -3,76 +3,126 @@
require
'spec_helper'
require
'spec_helper'
describe
API
::
ErrorTracking
do
describe
API
::
ErrorTracking
do
describe
"GET /projects/:id/error_tracking/settings"
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:setting
)
{
create
(
:project_error_tracking_setting
)
}
let
(
:setting
)
{
create
(
:project_error_tracking_setting
)
}
let
(
:project
)
{
setting
.
project
}
let
(
:project
)
{
setting
.
project
}
shared_examples
'returns project settings'
do
it
'returns correct project settings'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
eq
(
'active'
=>
setting
.
reload
.
enabled
,
'project_name'
=>
setting
.
project_name
,
'sentry_external_url'
=>
setting
.
sentry_external_url
,
'api_url'
=>
setting
.
api_url
)
end
end
def
make_request
shared_examples
'returns 404'
do
get
api
(
"/projects/
#{
project
.
id
}
/error_tracking/settings"
,
user
)
it
'returns correct project settings'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
json_response
[
'message'
])
.
to
eq
(
'404 Error Tracking Setting Not Found'
)
end
end
end
def
make_patch_request
(
active
)
describe
"PATCH /projects/:id/error_tracking/settings"
do
patch
api
(
"/projects/
#{
project
.
id
}
/error_tracking/settings"
,
user
),
params:
{
active:
active
}
def
make_patch_request
(
**
params
)
patch
api
(
"/projects/
#{
project
.
id
}
/error_tracking/settings"
,
user
),
params:
params
end
end
context
'when authenticated as maintainer'
do
context
'when authenticated as maintainer'
do
shared_examples
'returns project settings'
do
it
'returns correct project settings'
do
subject
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
eq
(
'active'
=>
setting
.
reload
.
enabled
,
'project_name'
=>
setting
.
project_name
,
'sentry_external_url'
=>
setting
.
sentry_external_url
,
'api_url'
=>
setting
.
api_url
)
end
end
before
do
before
do
project
.
add_maintainer
(
user
)
project
.
add_maintainer
(
user
)
end
end
context
'get settings'
do
subject
do
make_request
end
it_behaves_like
'returns project settings'
end
context
'patch settings'
do
context
'patch settings'
do
subject
do
subject
do
make_patch_request
(
false
)
make_patch_request
(
active:
false
)
end
end
it_behaves_like
'returns project settings'
it_behaves_like
'returns project settings'
it
'returns active is invalid if non boolean'
do
it
'returns active is invalid if non boolean'
do
make_patch_request
(
"randomstring"
)
make_patch_request
(
active:
"randomstring"
)
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'error'
])
expect
(
json_response
[
'error'
])
.
to
eq
(
'active is invalid'
)
.
to
eq
(
'active is invalid'
)
end
end
end
end
end
context
'without a project setting'
do
context
'without a project setting'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
before
do
project
.
add_maintainer
(
user
)
end
shared_examples
'returns 404'
do
context
'patch settings'
do
it
'returns correct project settings'
do
subject
do
subject
make_patch_request
(
active:
true
)
end
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
it_behaves_like
'returns 404'
expect
(
json_response
[
'message'
])
.
to
eq
(
'404 Error Tracking Setting Not Found'
)
end
end
end
end
end
context
'when authenticated as reporter'
do
before
do
project
.
add_reporter
(
user
)
end
it
'returns 403 for update request'
do
make_patch_request
(
active:
true
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
context
'when authenticated as developer'
do
before
do
project
.
add_developer
(
user
)
end
it
'returns 403 for update request'
do
make_patch_request
(
active:
true
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
context
'when authenticated as non-member'
do
it
'returns 404 for update request'
do
make_patch_request
(
active:
false
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'when unauthenticated'
do
let
(
:user
)
{
nil
}
it
'returns 401 for update request'
do
make_patch_request
(
active:
true
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
end
describe
"GET /projects/:id/error_tracking/settings"
do
def
make_request
get
api
(
"/projects/
#{
project
.
id
}
/error_tracking/settings"
,
user
)
end
context
'when authenticated as maintainer'
do
before
do
before
do
project
.
add_maintainer
(
user
)
project
.
add_maintainer
(
user
)
end
end
...
@@ -82,12 +132,20 @@ describe API::ErrorTracking do
...
@@ -82,12 +132,20 @@ describe API::ErrorTracking do
make_request
make_request
end
end
it_behaves_like
'returns
404
'
it_behaves_like
'returns
project settings
'
end
end
end
context
'patch settings'
do
context
'without a project setting'
do
let
(
:project
)
{
create
(
:project
)
}
before
do
project
.
add_maintainer
(
user
)
end
context
'get settings'
do
subject
do
subject
do
make_
patch_request
(
true
)
make_
request
end
end
it_behaves_like
'returns 404'
it_behaves_like
'returns 404'
...
@@ -104,12 +162,6 @@ describe API::ErrorTracking do
...
@@ -104,12 +162,6 @@ describe API::ErrorTracking do
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
it
'returns 403 for update request'
do
make_patch_request
(
true
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
end
context
'when authenticated as developer'
do
context
'when authenticated as developer'
do
...
@@ -122,12 +174,6 @@ describe API::ErrorTracking do
...
@@ -122,12 +174,6 @@ describe API::ErrorTracking do
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
it
'returns 403 for update request'
do
make_patch_request
(
true
)
expect
(
response
).
to
have_gitlab_http_status
(
:forbidden
)
end
end
end
context
'when authenticated as non-member'
do
context
'when authenticated as non-member'
do
...
@@ -136,12 +182,6 @@ describe API::ErrorTracking do
...
@@ -136,12 +182,6 @@ describe API::ErrorTracking do
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
it
'returns 404 for update request'
do
make_patch_request
(
false
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
end
context
'when unauthenticated'
do
context
'when unauthenticated'
do
...
@@ -152,12 +192,6 @@ describe API::ErrorTracking do
...
@@ -152,12 +192,6 @@ describe API::ErrorTracking do
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
it
'returns 401 for update request'
do
make_patch_request
(
true
)
expect
(
response
).
to
have_gitlab_http_status
(
:unauthorized
)
end
end
end
end
end
end
end
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