mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 21:56:55 -04:00
Account for finished planting when counting days of life
This commit is contained in:
committed by
Brenda Wallace
parent
10008ca30d
commit
b0a5223d97
@@ -40,7 +40,10 @@ module PredictPlanting
|
||||
end
|
||||
|
||||
def age_in_days
|
||||
(Time.zone.today - planted_at).to_i if planted_at.present?
|
||||
return if planted_at.blank?
|
||||
|
||||
known_last_day ||= finished_at || Time.zone.today
|
||||
(known_last_day - planted_at).to_i
|
||||
end
|
||||
|
||||
def percentage_grown
|
||||
|
||||
@@ -38,11 +38,11 @@ describe Planting do
|
||||
end
|
||||
|
||||
describe 'planting all finished' do
|
||||
let(:planting) { FactoryBot.create :planting, planted_at: 30.days.ago, finished_at: 1.day.ago, finished: true }
|
||||
let(:planting) { FactoryBot.create :planting, planted_at: 30.days.ago, finished_at: 10.days.ago, finished: true }
|
||||
|
||||
it { expect(planting.crop.median_lifespan).to eq(nil) }
|
||||
it { expect(planting.expected_lifespan).to eq(29) }
|
||||
it { expect(planting.age_in_days).to eq(30) }
|
||||
it { expect(planting.expected_lifespan).to eq(20) }
|
||||
it { expect(planting.age_in_days).to eq(20) }
|
||||
it { expect(planting.percentage_grown).to eq(100) }
|
||||
end
|
||||
end
|
||||
@@ -99,7 +99,7 @@ describe Planting do
|
||||
describe 'planted 30 days ago, finished 10 days ago' do
|
||||
let(:planting) { FactoryBot.create :planting, planted_at: 30.days.ago, finished_at: 10.days.ago }
|
||||
|
||||
it { expect(planting.age_in_days).to eq 30 }
|
||||
it { expect(planting.age_in_days).to eq 20 }
|
||||
it { expect(planting.percentage_grown).to eq 100 }
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user