Added some defaults when there are no deliverables.
This commit is contained in:
1 parent
990a10a4e8
commit
c433de9ec7
2 files changed
+24
-2
No files matched your search
@@ -34,7 +34,7 @@ class Budget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def budget
|
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
|
end
|
||||||
|
|
||||||
def budget_ratio
|
def budget_ratio
|
||||||
@@ -42,7 +42,7 @@ class Budget
|
|||||||
end
|
end
|
||||||
|
|
||||||
def spent
|
def spent
|
||||||
self.deliverables.collect(&:spent).inject { |sum, n| sum + n }
|
self.deliverables.collect(&:spent).inject { |sum, n| sum + n } || 0.0
|
||||||
end
|
end
|
||||||
|
|
||||||
def left
|
def left
|
||||||
|
|||||||
@@ -200,6 +200,17 @@ describe Budget,'.budget' do
|
|||||||
@budget = Budget.new(@project.id)
|
@budget = Budget.new(@project.id)
|
||||||
@budget.budget.should eql(5000.0)
|
@budget.budget.should eql(5000.0)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
describe Budget,'.budget_ratio' do
|
describe Budget,'.budget_ratio' do
|
||||||
@@ -277,4 +288,15 @@ describe Budget, '.spent' do
|
|||||||
|
|
||||||
@budget.spent.should eql(1500.0)
|
@budget.spent.should eql(1500.0)
|
||||||
end
|
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
|
end
|
||||||
Reference in new issue
Block a user