From 1637e5cdd1fa9a7e480604d2bf02ea09d9fdebc5 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Fri, 23 May 2008 16:38:27 -0700 Subject: [PATCH] Implemented more of the Deliverable calculations * Added deliverable.score * Added fixed_deliverable.score as 0 * Added deliverable.budget_ratio #1136 --- app/models/deliverable.rb | 6 +++++- app/models/fixed_deliverable.rb | 5 +++++ spec/models/deliverable_spec.rb | 22 ++++++++++++++++++++-- spec/models/fixed_deliverable_spec.rb | 8 ++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 spec/models/fixed_deliverable_spec.rb diff --git a/app/models/deliverable.rb b/app/models/deliverable.rb index cbdcdaf..8069f50 100644 --- a/app/models/deliverable.rb +++ b/app/models/deliverable.rb @@ -7,7 +7,7 @@ class Deliverable < ActiveRecord::Base # TODO: mocked def score - 0 + return self.progress - self.budget_ratio end # TODO: mocked @@ -29,6 +29,10 @@ class Deliverable < ActiveRecord::Base return (balance / total).round end + def budget_ratio + return ((self.spent / self.budget) * 100).round + end + # # These attributes can take a Dollar amount or a % # diff --git a/app/models/fixed_deliverable.rb b/app/models/fixed_deliverable.rb index 3d8b9d0..a88408b 100644 --- a/app/models/fixed_deliverable.rb +++ b/app/models/fixed_deliverable.rb @@ -1,3 +1,8 @@ class FixedDeliverable < Deliverable unloadable + + # Fixed rate bids should always have a budget score of 0. This is because the budget is managed by the contractor. + def score + 0 + end end diff --git a/spec/models/deliverable_spec.rb b/spec/models/deliverable_spec.rb index b8b76a7..fca962c 100644 --- a/spec/models/deliverable_spec.rb +++ b/spec/models/deliverable_spec.rb @@ -110,8 +110,24 @@ describe Deliverable, '.profit' do end end +describe Deliverable, '.budget_ratio' do + it 'should be the whole number of the budget spent' do + @deliverable = Deliverable.new({ :subject => 'test' }) + @deliverable.should_receive(:budget).and_return(3000.00) + @deliverable.should_receive(:spent).and_return(1000.00) + + @deliverable.budget_ratio.should eql(33) + end +end + describe Deliverable, '.score' do - it 'should' + it 'should be calculated by the progress and the budget usage' do + @deliverable = Deliverable.new({ :subject => 'test' }) + @deliverable.should_receive(:progress).and_return(75) + @deliverable.should_receive(:budget_ratio).and_return(33) + + @deliverable.score.should eql(42) + end end describe Deliverable, '.progress' do @@ -156,10 +172,12 @@ describe Deliverable, '.progress' do @deliverable.progress.should eql(100) end - it 'should not change when hours are clocked' + it 'should change if issues are assigned' + it 'should change if issues are unassigned' + it 'should change when a status changes' end diff --git a/spec/models/fixed_deliverable_spec.rb b/spec/models/fixed_deliverable_spec.rb new file mode 100644 index 0000000..c1c2e7a --- /dev/null +++ b/spec/models/fixed_deliverable_spec.rb @@ -0,0 +1,8 @@ +require File.dirname(__FILE__) + '/../spec_helper' + +describe FixedDeliverable, '.score' do + it 'should always be 0' do + @deliverable = FixedDeliverable.new({ :subject => 'test' }) + @deliverable.score.should eql(0) + end +end