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
c83caa94
Commit
c83caa94
authored
Jul 02, 2021
by
Eulyeon Ko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix due date condition
When a due date falls on the current date, it should not be considered expired.
parent
f4bf7be9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
10 deletions
+11
-10
app/models/milestone.rb
app/models/milestone.rb
+1
-1
spec/finders/milestones_finder_spec.rb
spec/finders/milestones_finder_spec.rb
+3
-3
spec/models/milestone_spec.rb
spec/models/milestone_spec.rb
+7
-6
No files found.
app/models/milestone.rb
View file @
c83caa94
...
...
@@ -123,7 +123,7 @@ class Milestone < ApplicationRecord
def
self
.
sort_with_expired_last
(
method
)
# NOTE: this is a custom ordering of milestones
# to prioritize displaying non-expired milestones and milestones without due dates
sorted
=
reorder
(
Arel
.
sql
(
'(CASE WHEN due_date IS NULL THEN 1 WHEN due_date > now() THEN 0 ELSE 2 END) ASC'
))
sorted
=
reorder
(
Arel
.
sql
(
"(CASE WHEN due_date IS NULL THEN 1 WHEN due_date >= '
#{
Date
.
current
}
' THEN 0 ELSE 2 END) ASC"
))
sorted
=
if
method
.
to_s
==
'expired_last_due_date_desc'
sorted
.
order
(
due_date: :desc
)
else
...
...
spec/finders/milestones_finder_spec.rb
View file @
c83caa94
...
...
@@ -3,7 +3,7 @@
require
'spec_helper'
RSpec
.
describe
MilestonesFinder
do
let_it_be
(
:now
)
{
Time
.
now
}
let_it_be
(
:now
)
{
Date
.
current
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:project_1
)
{
create
(
:project
,
namespace:
group
)
}
let_it_be
(
:project_2
)
{
create
(
:project
,
namespace:
group
)
}
...
...
@@ -11,7 +11,7 @@ RSpec.describe MilestonesFinder do
let_it_be
(
:milestone_4
)
{
create
(
:milestone
,
project:
project_2
,
state:
'active'
,
start_date:
now
+
4
.
days
,
due_date:
now
+
5
.
days
)
}
context
'without filters'
do
let_it_be
(
:milestone_1
)
{
create
(
:milestone
,
group:
group
,
title:
'one test'
,
start_date:
now
-
1
.
day
,
due_date:
now
)
}
let_it_be
(
:milestone_1
)
{
create
(
:milestone
,
group:
group
,
start_date:
now
-
1
.
day
,
due_date:
now
)
}
let_it_be
(
:milestone_3
)
{
create
(
:milestone
,
project:
project_1
,
state:
'active'
,
start_date:
now
+
2
.
days
)
}
let_it_be
(
:milestone_5
)
{
create
(
:milestone
,
group:
group
,
due_date:
now
-
2
.
days
)
}
...
...
@@ -47,7 +47,7 @@ RSpec.describe MilestonesFinder do
let
(
:extra_params
)
{
{
sort: :expired_last_due_date_asc
}
}
it
'current milestones are returned first, then milestones without due date followed by expired milestones, sorted by due date in ascending order'
do
expect
(
result
).
to
eq
([
milestone_
2
,
milestone_4
,
milestone_3
,
milestone_5
,
milestone_1
])
expect
(
result
).
to
eq
([
milestone_
1
,
milestone_2
,
milestone_4
,
milestone_3
,
milestone_5
])
end
end
end
...
...
spec/models/milestone_spec.rb
View file @
c83caa94
...
...
@@ -451,18 +451,19 @@ RSpec.describe Milestone do
end
describe
'.sort_with_expired_last'
do
let_it_be
(
:milestone_1
)
{
create
(
:milestone
,
title:
'Current 1'
,
due_date:
Time
.
current
+
1
.
day
)
}
let_it_be
(
:milestone_2
)
{
create
(
:milestone
,
title:
'Current 2'
,
due_date:
Time
.
current
+
2
.
days
)
}
let_it_be
(
:milestone
)
{
create
(
:milestone
,
title:
'Due today'
,
due_date:
Date
.
current
)
}
let_it_be
(
:milestone_1
)
{
create
(
:milestone
,
title:
'Current 1'
,
due_date:
Date
.
current
+
1
.
day
)
}
let_it_be
(
:milestone_2
)
{
create
(
:milestone
,
title:
'Current 2'
,
due_date:
Date
.
current
+
2
.
days
)
}
let_it_be
(
:milestone_3
)
{
create
(
:milestone
,
title:
'Without due date'
)
}
let_it_be
(
:milestone_4
)
{
create
(
:milestone
,
title:
'Expired 1'
,
due_date:
Tim
e
.
current
-
2
.
days
)
}
let_it_be
(
:milestone_5
)
{
create
(
:milestone
,
title:
'Expired 2'
,
due_date:
Tim
e
.
current
-
1
.
day
)
}
let_it_be
(
:milestone_4
)
{
create
(
:milestone
,
title:
'Expired 1'
,
due_date:
Dat
e
.
current
-
2
.
days
)
}
let_it_be
(
:milestone_5
)
{
create
(
:milestone
,
title:
'Expired 2'
,
due_date:
Dat
e
.
current
-
1
.
day
)
}
let_it_be
(
:milestone_6
)
{
create
(
:milestone
,
title:
'Without due date2'
)
}
context
'ordering by due_date ascending'
do
it
'sorts by due date in ascending order (ties broken by id in desc order)'
,
:aggregate_failures
do
expect
(
milestone_3
.
id
).
to
be
<
(
milestone_6
.
id
)
expect
(
described_class
.
sort_with_expired_last
(
:expired_last_due_date_asc
))
.
to
eq
([
milestone_1
,
milestone_2
,
milestone_6
,
milestone_3
,
milestone_4
,
milestone_5
])
.
to
eq
([
milestone
,
milestone
_1
,
milestone_2
,
milestone_6
,
milestone_3
,
milestone_4
,
milestone_5
])
end
end
...
...
@@ -470,7 +471,7 @@ RSpec.describe Milestone do
it
'sorts by due date in descending order (ties broken by id in desc order)'
,
:aggregate_failures
do
expect
(
milestone_3
.
id
).
to
be
<
(
milestone_6
.
id
)
expect
(
described_class
.
sort_with_expired_last
(
:expired_last_due_date_desc
))
.
to
eq
([
milestone_2
,
milestone_1
,
milestone_6
,
milestone_3
,
milestone_5
,
milestone_4
])
.
to
eq
([
milestone_2
,
milestone_1
,
milestone
,
milestone
_6
,
milestone_3
,
milestone_5
,
milestone_4
])
end
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