Added some defaults when there are no deliverables.
This commit is contained in:
@@ -34,7 +34,7 @@ class Budget
|
||||
end
|
||||
|
||||
def budget
|
||||
return self.deliverables.collect(&:budget).inject { |sum, n| sum + n}
|
||||
return self.deliverables.collect(&:budget).inject { |sum, n| sum + n} || 0.0
|
||||
end
|
||||
|
||||
def budget_ratio
|
||||
@@ -42,7 +42,7 @@ class Budget
|
||||
end
|
||||
|
||||
def spent
|
||||
self.deliverables.collect(&:spent).inject { |sum, n| sum + n }
|
||||
self.deliverables.collect(&:spent).inject { |sum, n| sum + n } || 0.0
|
||||
end
|
||||
|
||||
def left
|
||||
|
||||
@@ -200,6 +200,17 @@ describe Budget,'.budget' do
|
||||
@budget = Budget.new(@project.id)
|
||||
@budget.budget.should eql(5000.0)
|
||||
end
|
||||
|
||||
it 'should be 0 if there are no deliverables' do
|
||||
Deliverable.stub!(:find_all_by_project_id).and_return([])
|
||||
|
||||
@project = mock_model(Project)
|
||||
Project.stub!(:find).with(@project.id).and_return(@project)
|
||||
|
||||
@budget = Budget.new(@project.id)
|
||||
|
||||
@budget.budget.should eql(0.0)
|
||||
end
|
||||
end
|
||||
|
||||
describe Budget,'.budget_ratio' do
|
||||
@@ -277,4 +288,15 @@ describe Budget, '.spent' do
|
||||
|
||||
@budget.spent.should eql(1500.0)
|
||||
end
|
||||
|
||||
it 'should be 0 if there are no deliverables' do
|
||||
Deliverable.stub!(:find_all_by_project_id).and_return([])
|
||||
|
||||
@project = mock_model(Project)
|
||||
Project.stub!(:find).with(@project.id).and_return(@project)
|
||||
|
||||
@budget = Budget.new(@project.id)
|
||||
|
||||
@budget.spent.should eql(0.0)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user