add test for new helpers

This commit is contained in:
hitman 2017-03-16 22:32:11 +05:30 committed by Stella Rouzi
parent d9925f00e9
commit 8320f78d0b
2 changed files with 37 additions and 71 deletions

View file

@ -0,0 +1,37 @@
require 'spec_helper'
describe DateTimeHelper, type: :helper do
describe 'format_datetime' do
it 'returns nothing if there is no parameter' do
expect(format_datetime(nil)).to eq nil
end
it 'returns formatted string' do
datetime = Time.zone.local(2016, 05, 04, 11, 30)
expect(format_datetime(datetime)).to eq '2016-05-04 11:30'
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
end