From 8aac79be5311ff6e545f9756a60b4b1c07885a76 Mon Sep 17 00:00:00 2001 From: Marcel Amirault Date: Tue, 10 Jul 2018 10:49:28 +0000 Subject: Update time_helper.rb to fix output for exact minutes. --- app/helpers/time_helper.rb | 8 ++++++-- spec/helpers/time_helper_spec.rb | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/helpers/time_helper.rb b/app/helpers/time_helper.rb index 271e839692a..336385f6798 100644 --- a/app/helpers/time_helper.rb +++ b/app/helpers/time_helper.rb @@ -5,9 +5,13 @@ module TimeHelper seconds = interval_in_seconds - minutes * 60 if minutes >= 1 - "#{pluralize(minutes, "minute")} #{pluralize(seconds, "second")}" + if seconds % 60 == 0 + pluralize(minutes, "minute") + else + [pluralize(minutes, "minute"), pluralize(seconds, "second")].to_sentence + end else - "#{pluralize(seconds, "second")}" + pluralize(seconds, "second") end end diff --git a/spec/helpers/time_helper_spec.rb b/spec/helpers/time_helper_spec.rb index 21f35585367..0b371d69ecf 100644 --- a/spec/helpers/time_helper_spec.rb +++ b/spec/helpers/time_helper_spec.rb @@ -4,10 +4,12 @@ describe TimeHelper do describe "#time_interval_in_words" do it "returns minutes and seconds" do intervals_in_words = { - 100 => "1 minute 40 seconds", - 100.32 => "1 minute 40 seconds", - 121 => "2 minutes 1 second", - 3721 => "62 minutes 1 second", + 60 => "1 minute", + 100 => "1 minute and 40 seconds", + 100.32 => "1 minute and 40 seconds", + 120 => "2 minutes", + 121 => "2 minutes and 1 second", + 3721 => "62 minutes and 1 second", 0 => "0 seconds" } -- cgit v1.2.1