Implemented a lot more Budget calculations by building on the basics. #1137

This commit is contained in:
Eric Davis
2008-05-23 17:41:19 -07:00
parent 332925b31a
commit 6056069858
2 changed files with 97 additions and 2 deletions

View File

@@ -164,3 +164,80 @@ describe Budget, '.final_due_date' do
end
end
describe Budget, '.progress' do
it 'should be the weighted average by the deliverable progress and budget' do
@deliverable1 = mock_model(Deliverable, :project_id => @project, :budget => 2000.00, :progress => 50)
@deliverable2 = mock_model(Deliverable, :project_id => @project, :budget => 3000.00, :progress => 75)
@project = mock_model(Project)
@project.stub!(:deliverables).and_return([@deliverable1, @deliverable2])
Project.stub!(:find).with(@project.id).and_return(@project)
@budget = Budget.new(@project.id)
@budget.progress.should eql(65)
end
it 'should return 100 if there are no deliverables' do
@project = mock_model(Project)
@project.stub!(:deliverables).and_return([])
Project.stub!(:find).with(@project.id).and_return(@project)
@budget = Budget.new(@project.id)
@budget.progress.should eql(100)
end
end
describe Budget,'.budget' do
it 'should be the sum of all the deliverables budget' do
@deliverable1 = mock_model(Deliverable, :project_id => @project, :budget => 2000.00)
@deliverable2 = mock_model(Deliverable, :project_id => @project, :budget => 3000.00)
@project = mock_model(Project)
@project.stub!(:deliverables).and_return([@deliverable1, @deliverable2])
Project.stub!(:find).with(@project.id).and_return(@project)
@budget = Budget.new(@project.id)
@budget.budget.should eql(5000.0)
end
end
describe Budget,'.budget_ratio' do
it 'should be the whole number of the budget spent (out of 100)' 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(5000.00)
@budget.should_receive(:spent).and_return(2000.00)
@budget.budget_ratio.should eql(40)
end
end
describe Budget, '.score' do
it 'should be calculated by the progress and budget for the deliverables' do
@project = mock_model(Project)
Project.stub!(:find).with(@project.id).and_return(@project)
@budget = Budget.new(@project.id)
@budget.should_receive(:progress).and_return(65)
@budget.should_receive(:budget_ratio).and_return(40)
@budget.score.should eql(25)
end
end
describe Budget, '.left' do
it 'should be calculated by the total budget and total spent of the deliverables' 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(6000.0)
@budget.should_receive(:spent).and_return(4500.0)
@budget.left.should eql(1500.0)
end
end