mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Merge pull request #1150 from charliequinn/add-specs-for-show-time
Added specs for ApplicationHelper.show_time
This commit is contained in:
commit
529cfcf4c7
2 changed files with 30 additions and 9 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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'] }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue