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
Boxiang Sun
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
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
45 additions
and
48 deletions
+45
-48
app/controllers/admin/services_controller.rb
app/controllers/admin/services_controller.rb
+3
-1
app/models/service.rb
app/models/service.rb
+0
-10
app/services/projects/propagate_service.rb
app/services/projects/propagate_service.rb
+4
-4
app/workers/propagate_project_service_worker.rb
app/workers/propagate_project_service_worker.rb
+1
-1
spec/controllers/admin/services_controller_spec.rb
spec/controllers/admin/services_controller_spec.rb
+32
-0
spec/models/service_spec.rb
spec/models/service_spec.rb
+0
-27
spec/services/projects/propagate_service_spec.rb
spec/services/projects/propagate_service_spec.rb
+4
-4
spec/workers/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
...
@@ -15,7 +15,9 @@ class Admin::ServicesController < Admin::ApplicationController
end
end
def
update
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
,
redirect_to
admin_application_settings_services_path
,
notice:
'Application settings saved successfully'
notice:
'Application settings saved successfully'
else
else
...
...
app/models/service.rb
View file @
cf002738
...
@@ -254,16 +254,6 @@ class Service < ActiveRecord::Base
...
@@ -254,16 +254,6 @@ class Service < ActiveRecord::Base
service
service
end
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
private
def
cache_project_has_external_issue_tracker
def
cache_project_has_external_issue_tracker
...
...
app/services/projects/propagate_service.rb
View file @
cf002738
...
@@ -2,15 +2,15 @@ module Projects
...
@@ -2,15 +2,15 @@ module Projects
class
PropagateService
class
PropagateService
BATCH_SIZE
=
100
BATCH_SIZE
=
100
def
self
.
propagate
!
(
*
args
)
def
self
.
propagate
(
*
args
)
new
(
*
args
).
propagate
!
new
(
*
args
).
propagate
end
end
def
initialize
(
template
)
def
initialize
(
template
)
@template
=
template
@template
=
template
end
end
def
propagate
!
def
propagate
return
unless
@template
&
.
active
return
unless
@template
&
.
active
Rails
.
logger
.
info
(
"Propagating services for template
#{
@template
.
id
}
"
)
Rails
.
logger
.
info
(
"Propagating services for template
#{
@template
.
id
}
"
)
...
@@ -28,7 +28,7 @@ module Projects
...
@@ -28,7 +28,7 @@ module Projects
batch
.
each
{
|
project_id
|
create_from_template
(
project_id
)
}
batch
.
each
{
|
project_id
|
create_from_template
(
project_id
)
}
break
if
batch
.
count
<
BATCH_SIZE
break
if
batch
.
size
<
BATCH_SIZE
offset
+=
BATCH_SIZE
offset
+=
BATCH_SIZE
end
end
...
...
app/workers/propagate_project_service_worker.rb
View file @
cf002738
...
@@ -10,7 +10,7 @@ class PropagateProjectServiceWorker
...
@@ -10,7 +10,7 @@ class PropagateProjectServiceWorker
def
perform
(
template_id
)
def
perform
(
template_id
)
return
unless
try_obtain_lease_for
(
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
end
private
private
...
...
spec/controllers/admin/services_controller_spec.rb
View file @
cf002738
...
@@ -23,4 +23,36 @@ describe Admin::ServicesController do
...
@@ -23,4 +23,36 @@ describe Admin::ServicesController do
end
end
end
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
end
spec/models/service_spec.rb
View file @
cf002738
...
@@ -254,31 +254,4 @@ describe Service, models: true do
...
@@ -254,31 +254,4 @@ describe Service, models: true do
end
end
end
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
end
spec/services/projects/propagate_service_spec.rb
View file @
cf002738
...
@@ -18,7 +18,7 @@ describe Projects::PropagateService, services: true do
...
@@ -18,7 +18,7 @@ describe Projects::PropagateService, services: true do
let!
(
:project
)
{
create
(
:empty_project
)
}
let!
(
:project
)
{
create
(
:empty_project
)
}
it
'creates services for projects'
do
it
'creates services for projects'
do
expect
{
described_class
.
propagate
!
(
service_template
)
}.
expect
{
described_class
.
propagate
(
service_template
)
}.
to
change
{
Service
.
count
}.
by
(
1
)
to
change
{
Service
.
count
}.
by
(
1
)
end
end
...
@@ -36,7 +36,7 @@ describe Projects::PropagateService, services: true do
...
@@ -36,7 +36,7 @@ describe Projects::PropagateService, services: true do
Service
.
build_from_template
(
project
.
id
,
other_service
).
save!
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
)
to
change
{
Service
.
count
}.
by
(
1
)
end
end
...
@@ -55,12 +55,12 @@ describe Projects::PropagateService, services: true do
...
@@ -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
,
service_template
).
save!
Service
.
build_from_template
(
project
.
id
,
other_service
).
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
}
not_to
change
{
Service
.
count
}
end
end
it
'creates the service containing the template attributes'
do
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
)
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
...
@@ -21,7 +21,7 @@ describe PropagateProjectServiceWorker do
describe
'#perform'
do
describe
'#perform'
do
it
'calls the propagate service with the template'
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
)
subject
.
perform
(
service_template
.
id
)
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