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
72525fce
Commit
72525fce
authored
Mar 29, 2021
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use EditService for rotation changes
Add specs for failure case
parent
4d709949
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
ee/app/services/incident_management/oncall_schedules/update_service.rb
...es/incident_management/oncall_schedules/update_service.rb
+20
-11
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
...cident_management/oncall_schedules/update_service_spec.rb
+11
-1
No files found.
ee/app/services/incident_management/oncall_schedules/update_service.rb
View file @
72525fce
...
@@ -19,12 +19,16 @@ module IncidentManagement
...
@@ -19,12 +19,16 @@ module IncidentManagement
return
error_no_license
unless
available?
return
error_no_license
unless
available?
return
error_no_permissions
unless
allowed?
return
error_no_permissions
unless
allowed?
if
oncall_schedule
.
update
(
params
)
oncall_schedule
.
update!
(
params
)
update_rotation_active_periods
update_rotation_result
=
update_rotation_active_periods
success
(
oncall_schedule
)
else
if
update_rotation_result
.
respond_to?
(
:error?
)
&&
update_rotation_result
.
error?
error
(
oncall_schedule
.
errors
.
full_messages
.
to_sentenc
e
)
return
error
(
update_rotation_result
.
messag
e
)
end
end
success
(
oncall_schedule
)
rescue
ActiveRecord
::
RecordInvalid
=>
e
error
(
e
.
record
.
errors
.
full_messages
.
to_sentence
)
end
end
private
private
...
@@ -33,14 +37,19 @@ module IncidentManagement
...
@@ -33,14 +37,19 @@ module IncidentManagement
def
update_rotation_active_periods
def
update_rotation_active_periods
oncall_schedule
.
rotations
.
select
(
&
:has_shift_active_period?
).
each
do
|
rotation
|
oncall_schedule
.
rotations
.
select
(
&
:has_shift_active_period?
).
each
do
|
rotation
|
rotation
.
update!
(
service
=
IncidentManagement
::
OncallRotations
::
EditService
.
new
(
active_period_start:
new_rotation_active_period
(
rotation
.
active_period_start
).
strftime
(
'%H:%M'
),
rotation
,
active_period_end:
new_rotation_active_period
(
rotation
.
active_period_end
).
strftime
(
'%H:%M'
)
user
,
{
active_period_start:
new_rotation_active_period
(
rotation
.
active_period_start
).
strftime
(
'%H:%M'
),
active_period_end:
new_rotation_active_period
(
rotation
.
active_period_end
).
strftime
(
'%H:%M'
)
}
)
)
end
# TODO do we need to handle run update rotation job?
response
=
service
.
execute
# Should the above be moved to update rotation job?
break
(
response
)
if
response
.
error?
end
end
end
def
new_rotation_active_period
(
time_string
)
def
new_rotation_active_period
(
time_string
)
...
...
ee/spec/services/incident_management/oncall_schedules/update_service_spec.rb
View file @
72525fce
...
@@ -73,7 +73,7 @@ RSpec.describe IncidentManagement::OncallSchedules::UpdateService do
...
@@ -73,7 +73,7 @@ RSpec.describe IncidentManagement::OncallSchedules::UpdateService do
# Setting fixed timezone for rotation active period updates
# Setting fixed timezone for rotation active period updates
around
do
|
example
|
around
do
|
example
|
freeze_time
do
freeze_time
do
travel_to
Time
.
utc
(
2021
,
03
,
22
)
travel_to
Time
.
utc
(
2021
,
03
,
22
,
0
,
0
)
example
.
run
example
.
run
end
end
...
@@ -85,6 +85,16 @@ RSpec.describe IncidentManagement::OncallSchedules::UpdateService do
...
@@ -85,6 +85,16 @@ RSpec.describe IncidentManagement::OncallSchedules::UpdateService do
expect
{
execute
}.
to
change
{
time_from_time_column
(
oncall_rotation
.
reload
.
active_period_start
)
}.
from
(
'08:00'
).
to
(
'03:00'
)
expect
{
execute
}.
to
change
{
time_from_time_column
(
oncall_rotation
.
reload
.
active_period_start
)
}.
from
(
'08:00'
).
to
(
'03:00'
)
.
and
change
{
time_from_time_column
(
oncall_rotation
.
active_period_end
)
}.
from
(
'17:00'
).
to
(
'12:00'
)
.
and
change
{
time_from_time_column
(
oncall_rotation
.
active_period_end
)
}.
from
(
'17:00'
).
to
(
'12:00'
)
end
end
context
'error updating'
do
before
do
allow_next_instance_of
(
IncidentManagement
::
OncallRotations
::
EditService
)
do
|
edit_service
|
allow
(
edit_service
).
to
receive
(
:execute
).
and_return
(
double
(
error?:
true
,
message:
'Test something went wrong'
))
end
end
it_behaves_like
'error response'
,
'Test something went wrong'
end
end
end
def
time_from_time_column
(
attribute
)
def
time_from_time_column
(
attribute
)
...
...
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