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
f934b216
Commit
f934b216
authored
Oct 06, 2018
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check disabled_services when finding a service
parent
54c442af
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
11 deletions
+31
-11
app/models/project.rb
app/models/project.rb
+3
-3
spec/models/project_spec.rb
spec/models/project_spec.rb
+28
-8
No files found.
app/models/project.rb
View file @
f934b216
...
@@ -1088,9 +1088,7 @@ class Project < ActiveRecord::Base
...
@@ -1088,9 +1088,7 @@ class Project < ActiveRecord::Base
find_or_initialize_service
(
service_name
)
find_or_initialize_service
(
service_name
)
end
end
available_services
.
reject
do
|
service
|
available_services
.
compact
disabled_services
.
include?
(
service
.
to_param
)
end
end
end
def
disabled_services
def
disabled_services
...
@@ -1098,6 +1096,8 @@ class Project < ActiveRecord::Base
...
@@ -1098,6 +1096,8 @@ class Project < ActiveRecord::Base
end
end
def
find_or_initialize_service
(
name
)
def
find_or_initialize_service
(
name
)
return
if
disabled_services
.
include?
(
name
)
service
=
find_service
(
services
,
name
)
service
=
find_service
(
services
,
name
)
return
service
if
service
return
service
if
service
...
...
spec/models/project_spec.rb
View file @
f934b216
...
@@ -4037,6 +4037,21 @@ describe Project do
...
@@ -4037,6 +4037,21 @@ describe Project do
expect
(
result
).
to
be_empty
expect
(
result
).
to
be_empty
end
end
end
end
end
describe
"#find_or_initialize_services"
do
subject
{
build
(
:project
)
}
it
'returns only enabled services'
do
allow
(
Service
).
to
receive
(
:available_services_names
).
and_return
(
%w(prometheus pushover)
)
allow
(
subject
).
to
receive
(
:disabled_services
).
and_return
(
%w(prometheus)
)
services
=
subject
.
find_or_initialize_services
expect
(
services
.
count
).
to
eq
1
expect
(
services
).
to
include
(
PushoverService
)
end
end
describe
"#find_or_initialize_service"
do
describe
"#find_or_initialize_service"
do
subject
{
build
(
:project
)
}
subject
{
build
(
:project
)
}
...
@@ -4044,12 +4059,17 @@ describe Project do
...
@@ -4044,12 +4059,17 @@ describe Project do
it
'avoids N+1 database queries'
do
it
'avoids N+1 database queries'
do
allow
(
Service
).
to
receive
(
:available_services_names
).
and_return
(
%w(prometheus pushover)
)
allow
(
Service
).
to
receive
(
:available_services_names
).
and_return
(
%w(prometheus pushover)
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
pro
ject
.
find_or_initialize_service
(
'prometheus'
)
}.
count
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
sub
ject
.
find_or_initialize_service
(
'prometheus'
)
}.
count
allow
(
Service
).
to
receive
(
:available_services_names
).
and_call_original
allow
(
Service
).
to
receive
(
:available_services_names
).
and_call_original
expect
{
pro
ject
.
find_or_initialize_service
(
'prometheus'
)
}.
not_to
exceed_query_limit
(
control_count
)
expect
{
sub
ject
.
find_or_initialize_service
(
'prometheus'
)
}.
not_to
exceed_query_limit
(
control_count
)
end
end
it
'returns nil if service is disabled'
do
allow
(
subject
).
to
receive
(
:disabled_services
).
and_return
(
%w(prometheus)
)
expect
(
subject
.
find_or_initialize_service
(
'prometheus'
)).
to
be_nil
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