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
Hide 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,17 +28,9 @@ class Milestone < ActiveRecord::Base
...
@@ -28,17 +28,9 @@ class Milestone < ActiveRecord::Base
end
end
def
percent_complete
def
percent_complete
@percent_complete
||=
begin
((
self
.
issues
.
closed
.
count
*
100
)
/
self
.
issues
.
count
).
abs
total_i
=
self
.
issues
.
count
rescue
ZeroDivisionError
closed_i
=
self
.
issues
.
closed
.
count
100
if
total_i
>
0
(
closed_i
*
100
)
/
total_i
else
100
end
rescue
=>
ex
0
end
end
end
def
expires_at
def
expires_at
...
...
spec/models/milestone_spec.rb
View file @
580ce4f2
...
@@ -31,24 +31,33 @@ describe Milestone do
...
@@ -31,24 +31,33 @@ describe Milestone do
it
{
milestone
.
should
be_valid
}
it
{
milestone
.
should
be_valid
}
describe
"
Issues"
do
describe
"
#percent_complete"
do
before
do
it
"should not count open issues"
do
milestone
.
issues
<<
issue
milestone
.
issues
<<
issue
milestone
.
percent_complete
.
should
==
0
end
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
it
"should recover from dividing by zero"
do
issue
.
update_attributes
closed:
true
milestone
.
issues
.
should_receive
(
:count
).
and_return
(
0
)
milestone
.
percent_complete
.
should
==
100
milestone
.
percent_complete
.
should
==
100
end
end
end
end
describe
:expires_at
do
describe
"#expires_at"
do
before
do
it
"should be nil when due_date is unset"
do
milestone
.
update_attributes
due_date:
Date
.
today
+
1
.
day
milestone
.
update_attributes
(
due_date:
nil
)
milestone
.
expires_at
.
should
be_nil
end
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
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