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
580ce4f2
Commit
580ce4f2
authored
Aug 25, 2012
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor cleanup to Milestone model and spec
Back-ported from my still-in-progress major cleanup.
parent
232389f4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
20 deletions
+21
-20
app/models/milestone.rb
app/models/milestone.rb
+3
-11
spec/models/milestone_spec.rb
spec/models/milestone_spec.rb
+18
-9
No files found.
app/models/milestone.rb
View file @
580ce4f2
...
...
@@ -28,18 +28,10 @@ class Milestone < ActiveRecord::Base
end
def
percent_complete
@percent_complete
||=
begin
total_i
=
self
.
issues
.
count
closed_i
=
self
.
issues
.
closed
.
count
if
total_i
>
0
(
closed_i
*
100
)
/
total_i
else
((
self
.
issues
.
closed
.
count
*
100
)
/
self
.
issues
.
count
).
abs
rescue
ZeroDivisionError
100
end
rescue
=>
ex
0
end
end
def
expires_at
"expires at
#{
due_date
.
stamp
(
"Aug 21, 2011"
)
}
"
if
due_date
...
...
spec/models/milestone_spec.rb
View file @
580ce4f2
...
...
@@ -31,24 +31,33 @@ describe Milestone do
it
{
milestone
.
should
be_valid
}
describe
"
Issues"
do
before
do
describe
"
#percent_complete"
do
it
"should not count open issues"
do
milestone
.
issues
<<
issue
milestone
.
percent_complete
.
should
==
0
end
it
{
milestone
.
percent_complete
.
should
==
0
}
it
"should count closed issues"
do
issue
.
update_attributes
(
closed:
true
)
milestone
.
issues
<<
issue
milestone
.
percent_complete
.
should
==
100
end
it
do
issue
.
update_attributes
closed:
true
it
"should recover from dividing by zero"
do
milestone
.
issues
.
should_receive
(
:count
).
and_return
(
0
)
milestone
.
percent_complete
.
should
==
100
end
end
describe
:expires_at
do
before
do
milestone
.
update_attributes
due_date:
Date
.
today
+
1
.
day
describe
"#expires_at"
do
it
"should be nil when due_date is unset"
do
milestone
.
update_attributes
(
due_date:
nil
)
milestone
.
expires_at
.
should
be_nil
end
it
{
milestone
.
expires_at
.
should_not
be_nil
}
it
"should not be nil when due_date is set"
do
milestone
.
update_attributes
(
due_date:
Date
.
tomorrow
)
milestone
.
expires_at
.
should
be_present
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