Implemented Budget.final_due_date. #1137

This commit is contained in:
Eric Davis
2008-05-23 17:22:13 -07:00
parent 8c02ee4ade
commit 332925b31a
2 changed files with 68 additions and 4 deletions
+9 -4
View File
@@ -20,6 +20,15 @@ class Budget
return dates.sort[0]
end
def final_due_date
del = self.deliverables
return nil unless del.size > 0
dates = del.collect(&:due_date).delete_if { |d| d.blank?}
return dates.sort[-1]
end
def deliverables
return self.project.deliverables
end
@@ -40,10 +49,6 @@ class Budget
def score
end
# TODO
def final_due_date
end
# TODO
def profit
end
+59
View File
@@ -105,3 +105,62 @@ describe Budget, '.next_due_date' do
end
end
describe Budget, '.final_due_date' do
it 'should get the latest due date from the projects Deliverables' do
@tomorrow = Date.today + 1.days
@next_week = Date.today + 7.days
@deliverable1 = mock_model(Deliverable, :project_id => @project, :due_date => @next_week)
@deliverable2 = mock_model(Deliverable, :project_id => @project, :due_date => @tomorrow)
@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.final_due_date.should eql(@next_week)
end
it 'should return nil 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.final_due_date.should be_nil
end
it 'should not count dates that are nil' do
@tomorrow = Date.today + 1.days
@next_week = Date.today + 7.days
@deliverable1 = mock_model(Deliverable, :project_id => @project, :due_date => @next_week)
@deliverable2 = mock_model(Deliverable, :project_id => @project, :due_date => nil)
@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.final_due_date.should eql(@next_week)
end
it 'should not count dates that are empty' do
@tomorrow = Date.today + 1.days
@next_week = Date.today + 7.days
@deliverable1 = mock_model(Deliverable, :project_id => @project, :due_date => @next_week)
@deliverable2 = mock_model(Deliverable, :project_id => @project, :due_date => '')
@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.final_due_date.should eql(@next_week)
end
end