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
6710c874
Commit
6710c874
authored
Jan 07, 2019
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement error tracking configuration
Re-use operations controller which already handles tracing settings.
parent
191c20d7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
230 additions
and
14 deletions
+230
-14
app/controllers/projects/settings/operations_controller.rb
app/controllers/projects/settings/operations_controller.rb
+8
-1
app/helpers/projects_helper.rb
app/helpers/projects_helper.rb
+1
-1
app/models/project.rb
app/models/project.rb
+2
-0
app/services/projects/operations/update_service.rb
app/services/projects/operations/update_service.rb
+1
-1
spec/controllers/projects/settings/operations_controller_spec.rb
...ntrollers/projects/settings/operations_controller_spec.rb
+157
-11
spec/services/projects/operations/update_service_spec.rb
spec/services/projects/operations/update_service_spec.rb
+61
-0
No files found.
app/controllers/projects/settings/operations_controller.rb
View file @
6710c874
...
...
@@ -6,6 +6,8 @@ module Projects
before_action
:check_license
before_action
:authorize_update_environment!
helper_method
:error_tracking_setting
def
show
end
...
...
@@ -22,13 +24,18 @@ module Projects
private
def
error_tracking_setting
@error_tracking_setting
||=
project
.
error_tracking_setting
||
project
.
build_error_tracking_setting
end
def
update_params
params
.
require
(
:project
).
permit
(
permitted_project_params
)
end
# overridden in EE
def
permitted_project_params
{}
{
error_tracking_setting_attributes:
[
:enabled
,
:api_url
,
:token
]
}
end
def
check_license
...
...
app/helpers/projects_helper.rb
View file @
6710c874
...
...
@@ -285,7 +285,7 @@ module ProjectsHelper
# overridden in EE
def
settings_operations_available?
false
Feature
.
enabled?
(
:error_tracking
,
@project
)
&&
can?
(
current_user
,
:read_environment
,
@project
)
end
private
...
...
app/models/project.rb
View file @
6710c874
...
...
@@ -296,6 +296,8 @@ class Project < ActiveRecord::Base
allow_destroy:
true
,
reject_if:
->
(
attrs
)
{
attrs
[
:id
].
blank?
&&
attrs
[
:url
].
blank?
}
accepts_nested_attributes_for
:error_tracking_setting
,
update_only:
true
delegate
:name
,
to: :owner
,
allow_nil:
true
,
prefix:
true
delegate
:members
,
to: :team
,
prefix:
true
delegate
:add_user
,
:add_users
,
to: :team
...
...
app/services/projects/operations/update_service.rb
View file @
6710c874
...
...
@@ -12,7 +12,7 @@ module Projects
private
def
project_update_params
{}
params
.
slice
(
:error_tracking_setting_attributes
)
end
end
end
...
...
spec/controllers/projects/settings/operations_controller_spec.rb
View file @
6710c874
...
...
@@ -11,25 +11,171 @@ describe Projects::Settings::OperationsController do
project
.
add_maintainer
(
user
)
end
context
'error tracking'
do
describe
'GET #show'
do
it
'returns 404'
do
it
'renders show template'
do
get
:show
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
render_template
(
:show
)
end
context
'with existing setting'
do
let!
(
:error_tracking_setting
)
do
create
(
:project_error_tracking_setting
,
project:
project
)
end
it
'loads existing setting'
do
get
:show
,
params:
project_params
(
project
)
expect
(
controller
.
helpers
.
error_tracking_setting
)
.
to
eq
(
error_tracking_setting
)
end
end
context
'without an existing setting'
do
it
'builds a new setting'
do
get
:show
,
params:
project_params
(
project
)
expect
(
controller
.
helpers
.
error_tracking_setting
).
to
be_new_record
end
end
context
'with feature flag disabled'
do
before
do
stub_feature_flags
(
error_tracking:
false
)
end
it
'renders 404'
do
get
:show
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'with insufficient permissions'
do
before
do
project
.
add_reporter
(
user
)
end
it
'renders 404'
do
get
:show
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'as an anonymous user'
do
before
do
sign_out
(
user
)
end
it
'redirects to signup page'
do
get
:show
,
params:
project_params
(
project
)
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
describe
'PATCH #update'
do
it
'returns 404'
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_url:
'http://url'
,
token:
'token'
}
}
end
let
(
:error_tracking_permitted
)
do
ActionController
::
Parameters
.
new
(
error_tracking_params
).
permit!
end
context
'when update succeeds'
do
before
do
stub_operations_update_service_returning
(
status: :success
)
end
it
'shows a notice'
do
patch
:update
,
params:
project_params
(
project
,
error_tracking_params
)
expect
(
response
).
to
redirect_to
(
operations_url
)
expect
(
flash
[
:notice
]).
to
eq
_
(
'Your changes have been saved'
)
end
end
context
'when update fails'
do
before
do
stub_operations_update_service_returning
(
status: :error
)
end
it
'renders show page'
do
patch
:update
,
params:
project_params
(
project
,
error_tracking_params
)
expect
(
response
).
to
have_gitlab_http_status
(
:ok
)
expect
(
response
).
to
render_template
(
:show
)
end
end
context
'with feature flag disabled'
do
before
do
stub_feature_flags
(
error_tracking:
false
)
end
it
'renders 404'
do
patch
:update
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
end
context
'with insufficient permissions'
do
before
do
project
.
add_reporter
(
user
)
end
it
'renders 404'
do
patch
:update
,
params:
project_params
(
project
)
expect
(
response
).
to
have_gitlab_http_status
(
:not_found
)
end
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
)
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
private
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
)
end
end
private
def
project_params
(
project
)
{
namespace_id:
project
.
namespace
,
project_id:
project
}
def
project_params
(
project
,
params
=
{})
{
namespace_id:
project
.
namespace
,
project_id:
project
,
project:
params
}
end
end
spec/services/projects/operations/update_service_spec.rb
View file @
6710c874
...
...
@@ -11,6 +11,67 @@ describe Projects::Operations::UpdateService do
subject
{
described_class
.
new
(
project
,
user
,
params
)
}
describe
'#execute'
do
context
'error tracking'
do
context
'with existing error tracking setting'
do
let
(
:params
)
do
{
error_tracking_setting_attributes:
{
enabled:
false
,
api_url:
'http://url'
,
token:
'token'
}
}
end
before
do
create
(
:project_error_tracking_setting
,
project:
project
)
end
it
'updates the settings'
do
expect
(
result
[
:status
]).
to
eq
(
:success
)
project
.
reload
expect
(
project
.
error_tracking_setting
).
not_to
be_enabled
expect
(
project
.
error_tracking_setting
.
api_url
).
to
eq
(
'http://url'
)
expect
(
project
.
error_tracking_setting
.
token
).
to
eq
(
'token'
)
end
end
context
'without an existing error tracking setting'
do
let
(
:params
)
do
{
error_tracking_setting_attributes:
{
enabled:
true
,
api_url:
'http://url'
,
token:
'token'
}
}
end
it
'creates a setting'
do
expect
(
result
[
:status
]).
to
eq
(
:success
)
expect
(
project
.
error_tracking_setting
).
to
be_enabled
expect
(
project
.
error_tracking_setting
.
api_url
).
to
eq
(
'http://url'
)
expect
(
project
.
error_tracking_setting
.
token
).
to
eq
(
'token'
)
end
end
context
'with invalid parameters'
do
let
(
:params
)
{
{}
}
let!
(
:error_tracking_setting
)
do
create
(
:project_error_tracking_setting
,
project:
project
)
end
it
'does nothing'
do
expect
(
result
[
:status
]).
to
eq
(
:success
)
expect
(
project
.
reload
.
error_tracking_setting
)
.
to
eq
(
error_tracking_setting
)
end
end
end
context
'with inappropriate params'
do
let
(
:params
)
{
{
name:
''
}
}
...
...
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