osem-fcy/spec/helpers/date_time_helper_spec.rb
2018-04-04 10:28:10 -07:00

38 lines
884 B
Ruby

# frozen_string_literal: true
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, 0o5, 0o4, 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