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
Tatuya Kamada
gitlab-ce
Commits
8499de19
Commit
8499de19
authored
Aug 24, 2016
by
Alfredo Sumaran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure milestone counts work with no data
Commit originally written by @smcgivern
parent
19e2bf1c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
23 deletions
+22
-23
app/helpers/milestones_helper.rb
app/helpers/milestones_helper.rb
+5
-4
spec/helpers/milestones_helper_spec.rb
spec/helpers/milestones_helper_spec.rb
+17
-19
No files found.
app/helpers/milestones_helper.rb
View file @
8499de19
...
@@ -36,14 +36,15 @@ module MilestonesHelper
...
@@ -36,14 +36,15 @@ module MilestonesHelper
end
end
# Returns count of milestones for different states
# Returns count of milestones for different states
# Uses explicit hash keys as the 'opened' state URL params differs from the db value
# Uses explicit hash keys as the 'opened' state URL params differs from the db value
# and we need to add the total
# and we need to add the total
def
milestone_counts
(
milestones
)
def
milestone_counts
(
milestones
)
counts
=
milestones
.
reorder
(
nil
).
group
(
:state
).
count
counts
=
milestones
.
reorder
(
nil
).
group
(
:state
).
count
{
{
opened:
counts
[
'active'
],
opened:
counts
[
'active'
]
||
0
,
closed:
counts
[
'closed'
],
closed:
counts
[
'closed'
]
||
0
,
all:
counts
.
values
.
sum
all:
counts
.
values
.
sum
||
0
}
}
end
end
...
...
spec/helpers/milestones_helper_spec.rb
View file @
8499de19
...
@@ -3,33 +3,31 @@ require 'spec_helper'
...
@@ -3,33 +3,31 @@ require 'spec_helper'
describe
MilestonesHelper
do
describe
MilestonesHelper
do
describe
'#milestone_counts'
do
describe
'#milestone_counts'
do
let
(
:project
)
{
FactoryGirl
.
create
(
:project
)
}
let
(
:project
)
{
FactoryGirl
.
create
(
:project
)
}
let!
(
:milestone_1
)
{
FactoryGirl
.
create
(
:active_milestone
,
project:
project
)
}
let!
(
:milestone_2
)
{
FactoryGirl
.
create
(
:active_milestone
,
project:
project
)
}
let!
(
:milestone_3
)
{
FactoryGirl
.
create
(
:closed_milestone
,
project:
project
)
}
let
(
:counts
)
{
helper
.
milestone_counts
(
project
.
milestones
)
}
let
(
:counts
)
{
helper
.
milestone_counts
(
project
.
milestones
)
}
it
'returns a hash containing three items'
do
context
'when there are milestones'
do
expect
(
counts
.
length
).
to
eq
3
let!
(
:milestone_1
)
{
FactoryGirl
.
create
(
:active_milestone
,
project:
project
)
}
end
let!
(
:milestone_2
)
{
FactoryGirl
.
create
(
:active_milestone
,
project:
project
)
}
let!
(
:milestone_3
)
{
FactoryGirl
.
create
(
:closed_milestone
,
project:
project
)
}
it
'returns a hash containing "opened" key'
do
it
'returns the correct counts'
do
expect
(
counts
.
has_key?
(
:opened
)).
to
eq
true
expect
(
counts
).
to
eq
(
opened:
2
,
closed:
1
,
all:
3
)
end
end
end
it
'returns a hash containing "closed" key
'
do
context
'when there are only milestones of one type
'
do
expect
(
counts
.
has_key?
(
:closed
)).
to
eq
true
let!
(
:milestone_1
)
{
FactoryGirl
.
create
(
:active_milestone
,
project:
project
)
}
end
let!
(
:milestone_2
)
{
FactoryGirl
.
create
(
:active_milestone
,
project:
project
)
}
it
'returns a hash containing "all" key'
do
it
'returns the correct counts'
do
expect
(
counts
.
has_key?
(
:all
)).
to
eq
true
expect
(
counts
).
to
eq
(
opened:
2
,
closed:
0
,
all:
2
)
end
end
end
it
'shows "all" object is the sum of "opened" and "closed" object
s'
do
context
'when there are no milestone
s'
do
puts
counts
.
as_json
it
'returns the correct counts'
do
total
=
counts
[
:opened
]
+
counts
[
:closed
]
expect
(
counts
).
to
eq
(
opened:
0
,
closed:
0
,
all:
0
)
e
xpect
(
counts
[
:all
]).
to
eq
total
e
nd
end
end
end
end
end
end
\ No newline at end of file
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