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
0b65725f
Commit
0b65725f
authored
Apr 26, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
7a106e71
674e5e5b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
106 deletions
+110
-106
spec/controllers/projects/settings/operations_controller_spec.rb
...ntrollers/projects/settings/operations_controller_spec.rb
+110
-106
No files found.
spec/controllers/projects/settings/operations_controller_spec.rb
View file @
0b65725f
...
...
@@ -11,34 +11,63 @@ describe Projects::Settings::OperationsController do
project
.
add_maintainer
(
user
)
end
context
'error tracking'
do
describe
'GET #show'
do
it
'renders show template'
do
get
:show
,
params:
project_params
(
project
)
shared_examples
'PATCHable'
do
let
(
:operations_update_service
)
{
instance_double
(
::
Projects
::
Operations
::
UpdateService
)
}
let
(
:operations_url
)
{
project_settings_operations_url
(
project
)
}
let
(
:permitted_params
)
do
ActionController
::
Parameters
.
new
(
params
).
permit!
end
context
'format json'
do
context
'when update succeeds'
do
it
'returns success status'
do
stub_operations_update_service_returning
(
status: :success
)
patch
:update
,
params:
project_params
(
project
,
params
),
format: :json
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
render_template
(
:show
)
expect
(
json_response
).
to
eq
(
'status'
=>
'success'
)
expect
(
flash
[
:notice
]).
to
eq
(
'Your changes have been saved'
)
end
end
context
'with existing setting'
do
let!
(
:error_tracking_setting
)
do
create
(
:project_error_tracking_setting
,
project:
project
)
context
'when update fails'
do
it
'returns error'
do
stub_operations_update_service_returning
(
status: :error
,
message:
'error message'
)
patch
:update
,
params:
project_params
(
project
,
params
),
format: :json
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'message'
]).
to
eq
(
'error message'
)
end
end
end
it
'loads existing setting'
do
get
:show
,
params:
project_params
(
project
)
private
expect
(
controller
.
helpers
.
error_tracking_setting
)
.
to
eq
(
error_tracking_setting
)
def
stub_operations_update_service_returning
(
return_value
=
{})
expect
(
::
Projects
::
Operations
::
UpdateService
)
.
to
receive
(
:new
).
with
(
project
,
user
,
permitted_params
)
.
and_return
(
operations_update_service
)
expect
(
operations_update_service
).
to
receive
(
:execute
)
.
and_return
(
return_value
)
end
end
context
'without an existing setting
'
do
it
'builds a new setting
'
do
describe
'GET #show
'
do
it
'renders show template
'
do
get
:show
,
params:
project_params
(
project
)
expect
(
controller
.
helpers
.
error_tracking_setting
).
to
be_new_record
end
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
render_template
(
:show
)
end
context
'with insufficient permissions'
do
...
...
@@ -67,98 +96,73 @@ describe Projects::Settings::OperationsController do
end
describe
'PATCH #update'
do
let
(
:operations_update_service
)
{
spy
(
:operations_update_service
)
}
let
(
:operations_url
)
{
project_settings_operations_url
(
project
)
}
let
(
:error_tracking_params
)
do
{
error_tracking_setting_attributes:
{
enabled:
'1'
,
api_host:
'http://url'
,
token:
'token'
,
project:
{
slug:
'sentry-project'
,
name:
'Sentry Project'
,
organization_slug:
'sentry-org'
,
organization_name:
'Sentry Org'
}
}
}
end
let
(
:error_tracking_permitted
)
do
ActionController
::
Parameters
.
new
(
error_tracking_params
).
permit!
end
context
'format json'
do
context
'when update succeeds'
do
context
'with insufficient permissions'
do
before
do
stub_operations_update_service_returning
(
status: :success
)
project
.
add_reporter
(
user
)
end
it
'returns success status'
do
patch
:update
,
params:
project_params
(
project
,
error_tracking_params
),
format: :json
it
'renders 404'
do
patch
:update
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
json_response
).
to
eq
(
'status'
=>
'success'
)
expect
(
flash
[
:notice
]).
to
eq
(
'Your changes have been saved'
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'when update fails
'
do
context
'as an anonymous user
'
do
before
do
stub_operations_update_service_returning
(
status: :error
,
message:
'error message'
)
sign_out
(
user
)
end
it
'returns error'
do
patch
:update
,
params:
project_params
(
project
,
error_tracking_params
),
format: :json
it
'redirects to signup page'
do
patch
:update
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:bad_request
)
expect
(
json_response
[
'message'
]).
not_to
be_nil
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
context
'with insufficient permissions'
do
before
do
project
.
add_reporter
(
user
)
context
'error tracking'
do
describe
'GET #show'
do
context
'with existing setting'
do
let!
(
:error_tracking_setting
)
do
create
(
:project_error_tracking_setting
,
project:
project
)
end
it
'
renders 404
'
do
patch
:update
,
params:
project_params
(
project
)
it
'
loads existing setting
'
do
get
:show
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
expect
(
controller
.
helpers
.
error_tracking_setting
)
.
to
eq
(
error_tracking_setting
)
end
context
'as an anonymous user'
do
before
do
sign_out
(
user
)
end
it
'redirects to signup page'
do
patch
:update
,
params:
project_params
(
project
)
context
'without an existing setting'
do
it
'builds a new setting'
do
get
:show
,
params:
project_params
(
project
)
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
expect
(
controller
.
helpers
.
error_tracking_setting
).
to
be_new_record
end
end
end
private
describe
'PATCH #update'
do
let
(
:params
)
do
{
error_tracking_setting_attributes:
{
enabled:
'1'
,
api_host:
'http://url'
,
token:
'token'
,
project:
{
slug:
'sentry-project'
,
name:
'Sentry Project'
,
organization_slug:
'sentry-org'
,
organization_name:
'Sentry Org'
}
}
}
end
def
stub_operations_update_service_returning
(
return_value
=
{})
expect
(
::
Projects
::
Operations
::
UpdateService
)
.
to
receive
(
:new
).
with
(
project
,
user
,
error_tracking_permitted
)
.
and_return
(
operations_update_service
)
expect
(
operations_update_service
).
to
receive
(
:execute
)
.
and_return
(
return_value
)
it_behaves_like
'PATCHable'
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