mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 13:38:24 -04:00
Return a string from display_days_before_maturity
Sometimes we were returning a string, and sometimes we were returning an integer. We're only ever displaying the result, and this seems a little more consistent.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
module PlantingsHelper
|
||||
def display_days_before_maturity(planting)
|
||||
if planting.finished?
|
||||
0
|
||||
"0"
|
||||
elsif !planting.finished_at.nil?
|
||||
((p = planting.finished_at - Date.current).to_i) <= 0 ? 0 : p.to_i
|
||||
((p = planting.finished_at - Date.current).to_i) <= 0 ? "0" : p.to_i.to_s
|
||||
elsif planting.planted_at.nil? || planting.days_before_maturity.nil?
|
||||
"unknown"
|
||||
else
|
||||
((p = (planting.planted_at + planting.days_before_maturity) - Date.current).to_i <= 0) ? 0 : p.to_i
|
||||
((p = (planting.planted_at + planting.days_before_maturity) - Date.current).to_i <= 0) ? "0" : p.to_i.to_s
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -21,13 +21,13 @@ describe PlantingsHelper do
|
||||
days_before_maturity: 17
|
||||
)
|
||||
result = helper.display_days_before_maturity(planting)
|
||||
expect(result).to eq 17
|
||||
expect(result).to eq "17"
|
||||
end
|
||||
|
||||
it "handles completed plantings" do
|
||||
planting = FactoryGirl.build(:planting, finished: true)
|
||||
result = helper.display_days_before_maturity(planting)
|
||||
expect(result).to eq 0
|
||||
expect(result).to eq "0"
|
||||
end
|
||||
|
||||
it "handles plantings that should have finished" do
|
||||
@@ -35,10 +35,10 @@ describe PlantingsHelper do
|
||||
quantity: 5,
|
||||
planted_at: Date.new(0, 1, 1),
|
||||
finished_at: nil,
|
||||
days_before_maturity: 17
|
||||
days_before_maturity: "17"
|
||||
)
|
||||
result = helper.display_days_before_maturity(planting)
|
||||
expect(result).to eq 0
|
||||
expect(result).to eq "0"
|
||||
end
|
||||
|
||||
it "handles nil d_b_m and nil finished_at" do
|
||||
@@ -60,7 +60,7 @@ describe PlantingsHelper do
|
||||
days_before_maturity: nil
|
||||
)
|
||||
result = helper.display_days_before_maturity(planting)
|
||||
expect(result).to eq 5
|
||||
expect(result).to eq "5"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user