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
81476a98
Commit
81476a98
authored
Jul 12, 2018
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add method for updating Epic date fields
parent
88601cbb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
0 deletions
+66
-0
ee/app/models/ee/epic.rb
ee/app/models/ee/epic.rb
+16
-0
ee/spec/factories/epics.rb
ee/spec/factories/epics.rb
+9
-0
ee/spec/models/epic_spec.rb
ee/spec/models/epic_spec.rb
+41
-0
No files found.
ee/app/models/ee/epic.rb
View file @
81476a98
...
...
@@ -109,6 +109,12 @@ module EE
# Needed to use EntityDateHelper#remaining_days_in_words
alias_attribute
(
:due_date
,
:end_date
)
def
update_dates
self
.
start_date
=
compute_start_date
self
.
due_date
=
compute_due_date
save
if
changed?
end
# Earliest start date from issues' milestones
def
start_date_from_milestones
epic_issues
.
joins
(
issue: :milestone
).
minimum
(
'milestones.start_date'
)
...
...
@@ -155,5 +161,15 @@ module EE
def
banzai_render_context
(
field
)
super
.
merge
(
label_url_method: :group_epics_url
)
end
private
def
compute_start_date
start_date_is_fixed?
?
start_date_fixed
:
start_date_from_milestones
end
def
compute_due_date
due_date_is_fixed?
?
due_date_fixed
:
due_date_from_milestones
end
end
end
ee/spec/factories/epics.rb
View file @
81476a98
...
...
@@ -4,6 +4,15 @@ FactoryBot.define do
group
author
trait
:use_fixed_dates
do
start_date
{
Date
.
new
(
2010
,
1
,
1
)
}
start_date_fixed
{
Date
.
new
(
2010
,
1
,
1
)
}
start_date_is_fixed
true
end_date
{
Date
.
new
(
2010
,
1
,
3
)
}
due_date_fixed
{
Date
.
new
(
2010
,
1
,
3
)
}
due_date_is_fixed
true
end
factory
:labeled_epic
do
transient
do
labels
[]
...
...
ee/spec/models/epic_spec.rb
View file @
81476a98
...
...
@@ -85,6 +85,18 @@ describe Epic do
end
end
describe
'#start_date'
do
let
(
:date
)
{
Date
.
new
(
2000
,
1
,
1
)
}
context
'is set'
do
subject
{
build
(
:epic
,
:use_fixed_dates
,
start_date:
date
)
}
it
'returns as is'
do
expect
(
subject
.
start_date
).
to
eq
(
date
)
end
end
end
describe
'#start_date_from_milestones'
do
subject
{
create
(
:epic
)
}
let
(
:date
)
{
Date
.
new
(
2017
,
3
,
4
)
}
...
...
@@ -139,6 +151,35 @@ describe Epic do
end
end
describe
'#update_dates'
do
context
'fixed date is set'
do
subject
{
create
(
:epic
,
:use_fixed_dates
,
start_date:
nil
,
end_date:
nil
)
}
it
'updates to fixed date'
do
subject
.
update_dates
expect
(
subject
.
start_date
).
to
eq
(
subject
.
start_date_fixed
)
expect
(
subject
.
due_date
).
to
eq
(
subject
.
due_date_fixed
)
end
end
context
'fixed date is not set'
do
subject
{
create
(
:epic
,
start_date:
nil
,
end_date:
nil
)
}
let
(
:start_date
)
{
Date
.
new
(
2001
,
1
,
1
)
}
let
(
:due_date
)
{
Date
.
new
(
2002
,
1
,
1
)
}
it
'updates to milestone dates'
do
expect
(
subject
).
to
receive
(
:start_date_from_milestones
).
and_return
(
start_date
)
expect
(
subject
).
to
receive
(
:due_date_from_milestones
).
and_return
(
due_date
)
subject
.
update_dates
expect
(
subject
.
start_date
).
to
eq
(
start_date
)
expect
(
subject
.
due_date
).
to
eq
(
due_date
)
end
end
end
describe
'#issues'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
,
:private
)
}
...
...
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