Merge pull request #1150 from charliequinn/add-specs-for-show-time

Added specs for ApplicationHelper.show_time
This commit is contained in:
Christian Bruckmayer 2016-08-18 14:41:02 +02:00 committed by GitHub
commit 529cfcf4c7
2 changed files with 30 additions and 9 deletions

View file

@ -165,17 +165,16 @@ module ApplicationHelper
end
def show_time(length)
h = length / 60
min = length - h * 60
return '0 h 0 min' if length.blank?
if h != 0
if min != 0
"#{h} h #{min} min"
else
"#{h} h"
end
h, min = length.divmod(60)
if h == 0
"#{min.round} min"
elsif min == 0
"#{h} h"
else
"#{min} min"
"#{h} h #{min.round} min"
end
end

View file

@ -15,6 +15,28 @@ describe ApplicationHelper, type: :helper do
end
end
describe 'show_time' do
it 'when length > 60' do
expect(show_time(67)).to eq '1 h 7 min'
end
it 'when length = 60' do
expect(show_time(60)).to eq '1 h'
end
it 'when length < 60' do
expect(show_time(58)).to eq '58 min'
end
it 'when length > 60 and is a decimal number' do
expect(show_time(68.3)).to eq '1 h 8 min'
end
it 'when length is nil' do
expect(show_time(nil)).to eq '0 h 0 min'
end
end
describe 'show_roles' do
it 'formats the hash passed' do
roles = { 'organizer' => ['oSC16', 'oSC15'], 'cfp' => ['oSC16'] }