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
b0bf0012
Commit
b0bf0012
authored
Feb 24, 2021
by
Sean Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add active_particpants scope
Add specs
parent
0cf2eadc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
ee/app/models/incident_management/oncall_rotation.rb
ee/app/models/incident_management/oncall_rotation.rb
+3
-2
ee/spec/models/incident_management/oncall_rotation_spec.rb
ee/spec/models/incident_management/oncall_rotation_spec.rb
+11
-0
No files found.
ee/app/models/incident_management/oncall_rotation.rb
View file @
b0bf0012
...
...
@@ -32,6 +32,7 @@ module IncidentManagement
belongs_to
:schedule
,
class_name:
'OncallSchedule'
,
inverse_of:
'rotations'
,
foreign_key:
'oncall_schedule_id'
# Note! If changing the order of participants, also change the :with_shift_generation_associations scope.
has_many
:participants
,
->
{
order
(
id: :asc
)
},
class_name:
'OncallParticipant'
,
inverse_of: :rotation
has_many
:active_participants
,
->
{
not_removed
.
order
(
id: :asc
)
},
class_name:
'OncallParticipant'
,
inverse_of: :rotation
has_many
:users
,
through: :participants
has_many
:shifts
,
class_name:
'OncallShift'
,
inverse_of: :rotation
,
foreign_key: :rotation_id
...
...
@@ -49,9 +50,9 @@ module IncidentManagement
scope
:in_progress
,
->
{
where
(
'starts_at < :time AND (ends_at > :time OR ends_at IS NULL)'
,
time:
Time
.
current
)
}
scope
:except_ids
,
->
(
ids
)
{
where
.
not
(
id:
ids
)
}
scope
:with_shift_generation_associations
,
->
do
joins
(
:participants
,
:schedule
)
joins
(
:
active_
participants
,
:schedule
)
.
distinct
.
includes
(
:participants
,
:schedule
)
.
includes
(
:
active_
participants
,
:schedule
)
.
order
(
:id
,
'incident_management_oncall_participants.id ASC'
)
end
...
...
ee/spec/models/incident_management/oncall_rotation_spec.rb
View file @
b0bf0012
...
...
@@ -8,8 +8,19 @@ RSpec.describe IncidentManagement::OncallRotation do
describe
'.associations'
do
it
{
is_expected
.
to
belong_to
(
:schedule
).
class_name
(
'OncallSchedule'
).
inverse_of
(
:rotations
)
}
it
{
is_expected
.
to
have_many
(
:participants
).
order
(
id: :asc
).
class_name
(
'OncallParticipant'
).
inverse_of
(
:rotation
)
}
it
{
is_expected
.
to
have_many
(
:active_participants
).
order
(
id: :asc
).
class_name
(
'OncallParticipant'
).
inverse_of
(
:rotation
)
}
it
{
is_expected
.
to
have_many
(
:users
).
through
(
:participants
)
}
it
{
is_expected
.
to
have_many
(
:shifts
).
class_name
(
'OncallShift'
).
inverse_of
(
:rotation
)
}
describe
'.active_participants'
do
let
(
:rotation
)
{
create
(
:incident_management_oncall_rotation
,
schedule:
schedule
)
}
let
(
:participant
)
{
create
(
:incident_management_oncall_participant
,
rotation:
rotation
)
}
let
(
:removed_participant
)
{
create
(
:incident_management_oncall_participant
,
:removed
,
rotation:
rotation
)
}
subject
{
rotation
.
active_participants
}
it
{
is_expected
.
to
contain_exactly
(
participant
)
}
end
end
describe
'.validations'
do
...
...
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