From 9400225f65b283a6bf1ff4bca5dc1a9dcb87e8a3 Mon Sep 17 00:00:00 2001 From: Miles Gould Date: Wed, 30 Nov 2016 09:56:31 +0000 Subject: [PATCH] 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. --- app/helpers/plantings_helper.rb | 6 +++--- spec/helpers/plantings_helper_spec.rb | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/helpers/plantings_helper.rb b/app/helpers/plantings_helper.rb index 964b8fb76..f4d8d45be 100644 --- a/app/helpers/plantings_helper.rb +++ b/app/helpers/plantings_helper.rb @@ -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 diff --git a/spec/helpers/plantings_helper_spec.rb b/spec/helpers/plantings_helper_spec.rb index 2370bf53a..e776501b4 100644 --- a/spec/helpers/plantings_helper_spec.rb +++ b/spec/helpers/plantings_helper_spec.rb @@ -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