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

@ -4,62 +4,6 @@ describe ApplicationHelper, type: :helper do
let(:conference) { create(:conference) }
let(:event) { create(:event, program: conference.program) }
describe 'format_datetme' 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
describe 'show_roles' do
it 'formats the hash passed' do
roles = { 'organizer' => ['oSC16', 'oSC15'], 'cfp' => ['oSC16'] }
expect(show_roles(roles)).to eq 'Organizer (oSC16, oSC15), Cfp (oSC16)'
end
end
describe 'markdown' do
it 'should return empty string for nil' do
expect(markdown(nil)).to eq ''
end
it 'should return HTML for header markdown' do
expect(Redcarpet::Markdown).to receive(:new)
.with(Redcarpet::Render::HTML, autolink: true,
space_after_headers: true,
no_intra_emphasis: true)
.and_call_original
expect(markdown('# this is my header')).to eq "<h1>this is my header</h1>\n"
end
end
describe '#date_string' do
it 'when conference lasts 1 day' do
expect(date_string('Sun, 19 Feb 2017'.to_time, 'Sun, 19 Feb 2017'.to_time)).to eq 'February 19 2017'
@ -78,21 +22,6 @@ describe ApplicationHelper, type: :helper do
end
end
describe '#registered_text' do
describe 'returns correct string' do
it 'when there are no registrations' do
expect(registered_text(event)).to eq 'Registered: 0'
end
it 'when there is 1 registration' do
event.require_registration = true
event.max_attendees = 3
event.registrations << create(:registration, user: event.submitter)
expect(registered_text(event)).to eq 'Registered: 1/3'
end
end
end
describe '#concurrent_events' do
before :each do
@other_event = create(:event, program: conference.program, state: 'confirmed')

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