diff --git a/app/models/budget.rb b/app/models/budget.rb index 2d45fe2..17ee81f 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -109,7 +109,7 @@ class Budget # Dollar amount of time that has been logged to the project itself def amount_missing_on_issues - time_logs = TimeEntry.find_all_by_project_id_and_issue_id(self.project, nil) + time_logs = TimeEntry.find_all_by_project_id_and_issue_id(self.project.id, nil) return time_logs.collect(&:cost).sum end diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb index a8d914a..1cb84b6 100644 --- a/spec/models/budget_spec.rb +++ b/spec/models/budget_spec.rb @@ -437,3 +437,17 @@ describe Budget, '.profit' do @budget.profit.should eql(0.0) end end + +describe Budget, 'amount_missing_on_issues' do + it 'should caclulate the cost of the time logged to the project itself' do + project = mock_model(Project) + Project.stub!(:find).with(project.id).and_return(project) + budget = Budget.new(project.id) + + time_entry_one = mock_model(TimeEntry, :cost => 300.0) + time_entry_two = mock_model(TimeEntry, :cost => 500.0) + + TimeEntry.should_receive(:find_all_by_project_id_and_issue_id).with(project.id, nil).and_return([time_entry_one, time_entry_two]) + budget.amount_missing_on_issues.should eql(time_entry_one.cost + time_entry_two.cost) + end +end