BigW Consortium Gitlab

Commit 580ce4f2 by Robert Speicher

Minor cleanup to Milestone model and spec

Back-ported from my still-in-progress major cleanup.
parent 232389f4
...@@ -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
......
...@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment