Completed budget.spent calculation. #1137
This commit is contained in:
@@ -41,9 +41,8 @@ class Budget
|
|||||||
return ((self.spent / self.budget) * 100).round
|
return ((self.spent / self.budget) * 100).round
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO
|
|
||||||
def spent
|
def spent
|
||||||
0
|
self.deliverables.collect(&:spent).inject { |sum, n| sum + n }
|
||||||
end
|
end
|
||||||
|
|
||||||
def left
|
def left
|
||||||
|
|||||||
@@ -263,3 +263,18 @@ describe Budget, '.overruns' do
|
|||||||
@budget.overruns.should eql(1500.0)
|
@budget.overruns.should eql(1500.0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe Budget, '.spent' do
|
||||||
|
it 'should be calculated by the total spent of the deliverables' do
|
||||||
|
@deliverable1 = mock_model(HourlyDeliverable, :project_id => @project, :spent => 1000.00)
|
||||||
|
@deliverable2 = mock_model(HourlyDeliverable, :project_id => @project, :spent => 500.00)
|
||||||
|
Deliverable.stub!(:find_all_by_project_id).and_return([@deliverable1, @deliverable2])
|
||||||
|
|
||||||
|
@project = mock_model(Project)
|
||||||
|
Project.stub!(:find).with(@project.id).and_return(@project)
|
||||||
|
|
||||||
|
@budget = Budget.new(@project.id)
|
||||||
|
|
||||||
|
@budget.spent.should eql(1500.0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user