Cleanup of values when a project is empty. #1137

This commit is contained in:
Eric Davis
2008-05-28 13:13:08 -07:00
parent c433de9ec7
commit e96bdccb42
3 changed files with 20 additions and 4 deletions

View File

@@ -38,7 +38,12 @@ class Budget
end
def budget_ratio
return ((self.spent / self.budget) * 100).round
budget = self.budget # cache result
if budget > 0.0
return ((self.spent / budget) * 100).round
else
self.progress
end
end
def spent
@@ -50,7 +55,7 @@ class Budget
end
def overruns
if self.left > 0
if self.left >= 0
return 0
else
return self.left * -1

View File

@@ -20,10 +20,10 @@
Overruns: <%= h number_to_currency(@budget.overruns, :precision => 0) %>
</p>
<p>
Next Due Date: <%= h distance_of_time_in_words_to_now(@budget.next_due_date) %>
Next Due Date: <%= h distance_of_time_in_words_to_now(@budget.next_due_date) if @budget.next_due_date %>
</p>
<p>
Completion: <%= h distance_of_time_in_words_to_now(@budget.final_due_date) %>
Completion: <%= h distance_of_time_in_words_to_now(@budget.final_due_date) if @budget.final_due_date %>
</p>
<p>
Profit: TODO

View File

@@ -224,6 +224,17 @@ describe Budget,'.budget_ratio' do
@budget.should_receive(:spent).and_return(2000.00)
@budget.budget_ratio.should eql(40)
end
it 'should return progress if the budget is < 0' do
@project = mock_model(Project)
Project.stub!(:find).with(@project.id).and_return(@project)
@budget = Budget.new(@project.id)
@budget.should_receive(:budget).and_return(0.0)
@budget.should_receive(:progress).and_return(50)
@budget.budget_ratio.should eql(50)
end
end