Added Budget.profit. #1137
This commit is contained in:
@@ -311,3 +311,42 @@ describe Budget, '.spent' do
|
||||
@budget.spent.should eql(0.0)
|
||||
end
|
||||
end
|
||||
|
||||
describe Budget, '.profit' do
|
||||
it 'should be calculated by the total profit of the deliverables' do
|
||||
@project = mock_model(Project)
|
||||
@deliverable1 = mock_model(HourlyDeliverable, :project_id => @project, :profit => 2000.00, :profit_percent => nil)
|
||||
@deliverable2 = mock_model(HourlyDeliverable, :project_id => @project, :profit => 3000.00, :profit_percent => nil)
|
||||
|
||||
Deliverable.stub!(:find_all_by_project_id).and_return([@deliverable1, @deliverable2])
|
||||
Project.stub!(:find).with(@project.id).and_return(@project)
|
||||
|
||||
@budget = Budget.new(@project.id)
|
||||
|
||||
@budget.profit.should eql(5000.0)
|
||||
end
|
||||
|
||||
it 'should be calculated by the total profit of the deliverables with % amounts' do
|
||||
@project = mock_model(Project)
|
||||
@deliverable1 = mock_model(HourlyDeliverable, :project_id => @project, :profit_percent => 10, :budget => 2000.0, :profit => nil)
|
||||
@deliverable2 = mock_model(HourlyDeliverable, :project_id => @project, :profit_percent => 10, :budget => 1000.0, :profit => nil)
|
||||
|
||||
Deliverable.stub!(:find_all_by_project_id).and_return([@deliverable1, @deliverable2])
|
||||
Project.stub!(:find).with(@project.id).and_return(@project)
|
||||
|
||||
@budget = Budget.new(@project.id)
|
||||
|
||||
@budget.profit.should eql(300.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.profit.should eql(0.0)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user