BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
cf002738
Commit
cf002738
authored
May 04, 2017
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor a few things based on feedback
parent
78d05914
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
48 deletions
+45
-48
services_controller.rb
app/controllers/admin/services_controller.rb
+3
-1
service.rb
app/models/service.rb
+0
-10
propagate_service.rb
app/services/projects/propagate_service.rb
+4
-4
propagate_project_service_worker.rb
app/workers/propagate_project_service_worker.rb
+1
-1
services_controller_spec.rb
spec/controllers/admin/services_controller_spec.rb
+32
-0
service_spec.rb
spec/models/service_spec.rb
+0
-27
propagate_service_spec.rb
spec/services/projects/propagate_service_spec.rb
+4
-4
propagate_project_service_worker_spec.rb
spec/workers/propagate_project_service_worker_spec.rb
+1
-1
No files found.
app/controllers/admin/services_controller.rb
View file @
cf002738
...
...
@@ -15,7 +15,9 @@ class Admin::ServicesController < Admin::ApplicationController
end
def
update
if
service
.
update_and_propagate
(
service_params
[
:service
])
if
service
.
update_attributes
(
service_params
[
:service
])
PropagateProjectServiceWorker
.
perform_async
(
service
.
id
)
if
service
.
active?
redirect_to
admin_application_settings_services_path
,
notice:
'Application settings saved successfully'
else
...
...
app/models/service.rb
View file @
cf002738
...
...
@@ -254,16 +254,6 @@ class Service < ActiveRecord::Base
service
end
def
update_and_propagate
(
service_params
)
return
false
unless
update_attributes
(
service_params
)
if
service_params
[
:active
]
PropagateProjectServiceWorker
.
perform_async
(
id
)
end
true
end
private
def
cache_project_has_external_issue_tracker
...
...
app/services/projects/propagate_service.rb
View file @
cf002738
...
...
@@ -2,15 +2,15 @@ module Projects
class
PropagateService
BATCH_SIZE
=
100
def
self
.
propagate
!
(
*
args
)
new
(
*
args
).
propagate
!
def
self
.
propagate
(
*
args
)
new
(
*
args
).
propagate
end
def
initialize
(
template
)
@template
=
template
end
def
propagate
!
def
propagate
return
unless
@template
&
.
active
Rails
.
logger
.
info
(
"Propagating services for template
#{
@template
.
id
}
"
)
...
...
@@ -28,7 +28,7 @@ module Projects
batch
.
each
{
|
project_id
|
create_from_template
(
project_id
)
}
break
if
batch
.
count
<
BATCH_SIZE
break
if
batch
.
size
<
BATCH_SIZE
offset
+=
BATCH_SIZE
end
...
...
app/workers/propagate_project_service_worker.rb
View file @
cf002738
...
...
@@ -10,7 +10,7 @@ class PropagateProjectServiceWorker
def
perform
(
template_id
)
return
unless
try_obtain_lease_for
(
template_id
)
Projects
::
PropagateService
.
propagate
!
(
Service
.
find_by
(
id:
template_id
))
Projects
::
PropagateService
.
propagate
(
Service
.
find_by
(
id:
template_id
))
end
private
...
...
spec/controllers/admin/services_controller_spec.rb
View file @
cf002738
...
...
@@ -23,4 +23,36 @@ describe Admin::ServicesController do
end
end
end
describe
"#update"
do
let
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:service
)
do
RedmineService
.
create
(
project:
project
,
active:
false
,
template:
true
,
properties:
{
project_url:
'http://abc'
,
issues_url:
'http://abc'
,
new_issue_url:
'http://abc'
}
)
end
it
'updates the service params successfully and calls the propagation worker'
do
expect
(
PropagateProjectServiceWorker
).
to
receive
(
:perform_async
).
with
(
service
.
id
)
put
:update
,
id:
service
.
id
,
service:
{
active:
true
}
expect
(
response
).
to
have_http_status
(
302
)
end
it
'updates the service params successfully'
do
expect
(
PropagateProjectServiceWorker
).
not_to
receive
(
:perform_async
)
put
:update
,
id:
service
.
id
,
service:
{
properties:
{}
}
expect
(
response
).
to
have_http_status
(
302
)
end
end
end
spec/models/service_spec.rb
View file @
cf002738
...
...
@@ -254,31 +254,4 @@ describe Service, models: true do
end
end
end
describe
"#update_and_propagate"
do
let
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:service
)
do
RedmineService
.
create
(
project:
project
,
active:
false
,
properties:
{
project_url:
'http://abc'
,
issues_url:
'http://abc'
,
new_issue_url:
'http://abc'
}
)
end
it
'updates the service params successfully and calls the propagation worker'
do
expect
(
PropagateProjectServiceWorker
).
to
receive
(
:perform_async
).
with
(
service
.
id
)
expect
(
service
.
update_and_propagate
(
active:
true
)).
to
be
true
end
it
'updates the service params successfully'
do
expect
(
PropagateProjectServiceWorker
).
not_to
receive
(
:perform_async
)
expect
(
service
.
update_and_propagate
(
properties:
{})).
to
be
true
end
end
end
spec/services/projects/propagate_service_spec.rb
View file @
cf002738
...
...
@@ -18,7 +18,7 @@ describe Projects::PropagateService, services: true do
let!
(
:project
)
{
create
(
:empty_project
)
}
it
'creates services for projects'
do
expect
{
described_class
.
propagate
!
(
service_template
)
}.
expect
{
described_class
.
propagate
(
service_template
)
}.
to
change
{
Service
.
count
}.
by
(
1
)
end
...
...
@@ -36,7 +36,7 @@ describe Projects::PropagateService, services: true do
Service
.
build_from_template
(
project
.
id
,
other_service
).
save!
expect
{
described_class
.
propagate
!
(
service_template
)
}.
expect
{
described_class
.
propagate
(
service_template
)
}.
to
change
{
Service
.
count
}.
by
(
1
)
end
...
...
@@ -55,12 +55,12 @@ describe Projects::PropagateService, services: true do
Service
.
build_from_template
(
project
.
id
,
service_template
).
save!
Service
.
build_from_template
(
project
.
id
,
other_service
).
save!
expect
{
described_class
.
propagate
!
(
service_template
)
}.
expect
{
described_class
.
propagate
(
service_template
)
}.
not_to
change
{
Service
.
count
}
end
it
'creates the service containing the template attributes'
do
described_class
.
propagate
!
(
service_template
)
described_class
.
propagate
(
service_template
)
service
=
Service
.
find_by
(
type:
service_template
.
type
,
template:
false
)
...
...
spec/workers/propagate_project_service_worker_spec.rb
View file @
cf002738
...
...
@@ -21,7 +21,7 @@ describe PropagateProjectServiceWorker do
describe
'#perform'
do
it
'calls the propagate service with the template'
do
expect
(
Projects
::
PropagateService
).
to
receive
(
:propagate
!
).
with
(
service_template
)
expect
(
Projects
::
PropagateService
).
to
receive
(
:propagate
).
with
(
service_template
)
subject
.
perform
(
service_template
.
id
)
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