mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-13 02:35:22 -04:00
Tweak specs, implementation properly
This commit is contained in:
@@ -109,17 +109,17 @@ class Planting < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def planted?(current_date = DateTime.now)
|
||||
def planted?(current_date = Date.today)
|
||||
planted_at.present? && current_date.to_date >= planted_at
|
||||
end
|
||||
|
||||
def percentage_grown(current_date = DateTime.now)
|
||||
def percentage_grown(current_date = Date.today)
|
||||
return nil unless days_before_maturity && planted?(current_date)
|
||||
|
||||
days = (current_date.to_date - planted_at.to_date).to_i
|
||||
|
||||
return 0 if current_date < planted_at
|
||||
return 100 if days > days_before_maturity
|
||||
|
||||
days = current_date - planted_at
|
||||
percent = (days/days_before_maturity*100).to_i
|
||||
|
||||
if percent >= 100
|
||||
|
||||
@@ -57,13 +57,13 @@ describe Planting do
|
||||
|
||||
now_earlier_than_planting = 2.days.ago
|
||||
|
||||
@planting.percentage_grown(now_earlier_than_planting).should be 0
|
||||
@planting.percentage_grown(now_earlier_than_planting).should be nil
|
||||
end
|
||||
|
||||
it 'should reflect the current growth' do
|
||||
@planting = FactoryGirl.build(:planting, days_before_maturity: 10, planted_at: 4.days.ago)
|
||||
|
||||
@planting.percentage_grown.should be 40
|
||||
@planting.percentage_grown(Date.today).should be 40
|
||||
end
|
||||
|
||||
it 'should not be calculated for unplanted plantings' do
|
||||
|
||||
Reference in New Issue
Block a user