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:
Miles Gould
2016-11-30 09:56:31 +00:00
parent b0b864a5d4
commit 9400225f65
2 changed files with 8 additions and 8 deletions

View File

@@ -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

View File

@@ -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