Wrapped Deliverable.budget getter so it will return 0 if the budget is nil. #1708

This commit is contained in:
Eric Davis
2008-10-15 09:43:22 -07:00
parent 71060831fc
commit 52e80b4f56
2 changed files with 19 additions and 0 deletions
+10
View File
@@ -123,6 +123,16 @@ class Deliverable < ActiveRecord::Base
end
end
# Wrap the budget getter so it returns 0 if budget is nil
def budget
raw_budget = read_attribute(:budget)
unless raw_budget.nil?
return raw_budget
else
return 0
end
end
# Amount of the budget remaining to be spent
def budget_remaining
return self.budget - self.spent
+9
View File
@@ -120,6 +120,15 @@ describe Deliverable, '.budget_ratio' do
end
end
describe Deliverable, '.budget' do
it 'should return 0 if the budget is nil' do
@deliverable = Deliverable.new({ :subject => 'test' })
@deliverable.budget.should eql(0)
@deliverable.read_attribute(:budget).should eql(nil)
end
end
describe Deliverable, '.score' do
it 'should be calculated by the progress and the budget usage' do
@deliverable = Deliverable.new({ :subject => 'test' })