From 322013f4a01927519aae0d4711915d10c47bdcdd Mon Sep 17 00:00:00 2001
From: Eric Davis
- Profit: TODO + Profit: <%= h number_to_currency(@budget.profit, :precision => 0) %>
diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb index b78afeb..0bfb8b0 100644 --- a/spec/models/budget_spec.rb +++ b/spec/models/budget_spec.rb @@ -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