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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
7fd9e39d
Commit
7fd9e39d
authored
Mar 27, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When a Service templates are invalid newly created projects will have them inactive
parent
bf4a3af0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
8 deletions
+27
-8
app/models/service.rb
app/models/service.rb
+1
-0
app/services/projects/create_service.rb
app/services/projects/create_service.rb
+3
-1
spec/models/service_spec.rb
spec/models/service_spec.rb
+15
-0
spec/services/projects/create_service_spec.rb
spec/services/projects/create_service_spec.rb
+8
-7
No files found.
app/models/service.rb
View file @
7fd9e39d
...
...
@@ -273,6 +273,7 @@ class Service < ActiveRecord::Base
def
self
.
build_from_template
(
project_id
,
template
)
service
=
template
.
dup
service
.
active
=
false
unless
service
.
valid?
service
.
template
=
false
service
.
project_id
=
project_id
service
...
...
app/services/projects/create_service.rb
View file @
7fd9e39d
...
...
@@ -133,8 +133,10 @@ module Projects
def
fail
(
error
:)
message
=
"Unable to save project. Error:
#{
error
}
"
log_message
=
message
.
dup
Rails
.
logger
.
error
(
message
)
log_message
<<
" Project ID:
#{
@project
.
id
}
"
if
@project
&
.
id
Rails
.
logger
.
error
(
log_message
)
if
@project
@project
.
errors
.
add
(
:base
,
message
)
...
...
spec/models/service_spec.rb
View file @
7fd9e39d
...
...
@@ -58,6 +58,21 @@ describe Service do
end
describe
"Template"
do
describe
'.build_from_template'
do
context
'when template is invalid'
do
it
'sets service template to inactive when template is invalid'
do
project
=
create
(
:project
)
template
=
JiraService
.
new
(
template:
true
,
active:
true
)
template
.
save
(
validate:
false
)
service
=
described_class
.
build_from_template
(
project
.
id
,
template
)
expect
(
service
).
to
be_valid
expect
(
service
.
active
).
to
be
false
end
end
end
describe
"for pushover service"
do
let!
(
:service_template
)
do
PushoverService
.
create
(
...
...
spec/services/projects/create_service_spec.rb
View file @
7fd9e39d
...
...
@@ -71,14 +71,14 @@ describe Projects::CreateService, '#execute' do
expect
(
create_project
(
user
,
opts
)).
to
eq
(
nil
)
end
it
'
handles invalid servic
e'
do
it
'
sets invalid service as inactiv
e'
do
create
(
:service
,
type:
'JiraService'
,
project:
nil
,
template:
true
,
active:
true
)
project
=
create_project
(
user
,
opts
)
service
=
project
.
services
.
first
expect
(
project
).
not_to
be_persisted
expect
(
project
.
errors
.
full_messages_for
(
:base
).
first
).
to
match
(
/Unable to save project. Error: Unable to save JiraService/
)
expect
(
project
.
services
.
count
).
to
eq
0
expect
(
project
).
to
be_persisted
expect
(
service
.
active
).
to
be
false
end
end
...
...
@@ -242,14 +242,15 @@ describe Projects::CreateService, '#execute' do
end
context
'when a bad service template is created'
do
it
'
reports an error in the imported project
'
do
it
'
sets service to be inactive
'
do
opts
[
:import_url
]
=
'http://www.gitlab.com/gitlab-org/gitlab-ce'
create
(
:service
,
type:
'DroneCiService'
,
project:
nil
,
template:
true
,
active:
true
)
project
=
create_project
(
user
,
opts
)
service
=
project
.
services
.
first
expect
(
project
.
errors
.
full_messages_for
(
:base
).
first
).
to
match
(
/Unable to save project. Error: Unable to save DroneCiService/
)
expect
(
project
.
services
.
count
).
to
eq
0
expect
(
project
).
to
be_persisted
expect
(
service
.
active
).
to
be
false
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