BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
da7c1444
Commit
da7c1444
authored
Jul 25, 2016
by
Dan Rowden
Committed by
Alfredo Sumaran
Sep 07, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated milestone count helper plus tests
parent
c1f508b0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
5 deletions
+43
-5
milestones_helper.rb
app/helpers/milestones_helper.rb
+3
-3
_milestones_filter.html.haml
app/views/shared/_milestones_filter.html.haml
+1
-1
milestones.rb
spec/factories/milestones.rb
+6
-1
milestones_helper_spec.rb
spec/helpers/milestones_helper_spec.rb
+33
-0
No files found.
app/helpers/milestones_helper.rb
View file @
da7c1444
...
@@ -38,12 +38,12 @@ module MilestonesHelper
...
@@ -38,12 +38,12 @@ module MilestonesHelper
# 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
(
project
:
)
def
milestone_counts
(
milestones
)
counts
=
@project
.
milestones
.
reorder
(
nil
).
group
(
:state
).
count
()
counts
=
milestones
.
reorder
(
nil
).
group
(
:state
).
count
{
{
opened:
counts
[
'active'
],
opened:
counts
[
'active'
],
closed:
counts
[
'closed'
],
closed:
counts
[
'closed'
],
all:
counts
[
'active'
]
+
counts
[
'closed'
]
all:
counts
.
values
.
sum
}
}
end
end
...
...
app/views/shared/_milestones_filter.html.haml
View file @
da7c1444
-
counts
=
milestone_counts
(
project:
@project
)
-
counts
=
milestone_counts
(
@project
.
milestones
)
%ul
.nav-links
%ul
.nav-links
%li
{
class:
(
"active"
if
params
[
:state
].
blank?
||
params
[
:state
]
==
'opened'
)}
%li
{
class:
(
"active"
if
params
[
:state
].
blank?
||
params
[
:state
]
==
'opened'
)}
...
...
spec/factories/milestones.rb
View file @
da7c1444
...
@@ -3,10 +3,15 @@ FactoryGirl.define do
...
@@ -3,10 +3,15 @@ FactoryGirl.define do
title
title
project
project
trait
:active
do
state
"active"
end
trait
:closed
do
trait
:closed
do
state
:closed
state
"closed"
end
end
factory
:active_milestone
,
traits:
[
:active
]
factory
:closed_milestone
,
traits:
[
:closed
]
factory
:closed_milestone
,
traits:
[
:closed
]
end
end
end
end
spec/helpers/milestones_helper_spec.rb
0 → 100644
View file @
da7c1444
require
'spec_helper'
describe
MilestonesHelper
do
describe
'#milestone_counts'
do
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
)
}
it
'returns a hash containing three items'
do
expect
(
counts
.
length
).
to
eq
3
end
it
'returns a hash containing "opened" key'
do
expect
(
counts
.
has_key?
(
:opened
)).
to
eq
true
end
it
'returns a hash containing "closed" key'
do
expect
(
counts
.
has_key?
(
:closed
)).
to
eq
true
end
it
'returns a hash containing "all" key'
do
expect
(
counts
.
has_key?
(
:all
)).
to
eq
true
end
# This throws a "NoMethodError: undefined method `+' for nil:NilClass" error for line 27; can't figure out why it can't find the keys in the hash
# it 'shows "all" object is the sum of "opened" and "closed" objects' do
# total = counts[:opened] + counts[:closed]
# expect(counts[:all]).to eq total
# 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