1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
require 'spec_helper'
describe Icalendar::Parser do
subject { described_class.new source, false }
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', fn) }
describe '#parse' do
context 'single_event.ics' do
let(:fn) { 'single_event.ics' }
it 'returns an array of calendars' do
parsed = subject.parse
expect(parsed).to be_instance_of Array
expect(parsed.count).to eq 1
expect(parsed[0]).to be_instance_of Icalendar::Calendar
end
it 'properly splits multi-valued lines' do
event = subject.parse.first.events.first
expect(event.geo).to eq [37.386013,-122.0829322]
end
it 'saves params' do
event = subject.parse.first.events.first
expect(event.dtstart.ical_params).to eq('tzid' => ['US-Mountain'])
end
end
context 'recurrence.ics' do
let(:fn) { 'recurrence.ics' }
it 'correctly parses the exdate array' do
event = subject.parse.first.events.first
ics = event.to_ical
expect(ics).to match 'EXDATE;VALUE=DATE:20120323,20130323'
end
end
context 'event.ics' do
let(:fn) { 'event.ics' }
before { subject.component_class = Icalendar::Event }
it 'returns an array of events' do
parsed = subject.parse
expect(parsed).to be_instance_of Array
expect(parsed.count).to be 1
expect(parsed[0]).to be_instance_of Icalendar::Event
end
end
context 'events.ics' do
let(:fn) { 'two_events.ics' }
before { subject.component_class = Icalendar::Event }
it 'returns an array of events' do
events = subject.parse
expect(events.count).to be 2
expect(events.first.uid).to eq("bsuidfortestabc123")
expect(events.last.uid).to eq("uid-1234-uid-4321")
end
end
context 'tzid_search.ics' do
let(:fn) { 'tzid_search.ics' }
it 'correctly sets the weird tzid' do
parsed = subject.parse
event = parsed.first.events.first
expect(event.dtstart.utc).to eq Time.parse("20180104T150000Z")
end
end
context 'custom_component.ics' do
let(:fn) { 'custom_component.ics' }
it 'correctly handles custom named components' do
parsed = subject.parse
calendar = parsed.first
expect(calendar.custom_component('x_event_series').size).to eq 1
expect(calendar.custom_component('X-EVENT-SERIES').size).to eq 1
end
end
end
describe '#parse with bad line' do
let(:fn) { 'single_event_bad_line.ics' }
it 'returns an array of calendars' do
parsed = subject.parse
expect(parsed).to be_instance_of Array
expect(parsed.count).to eq 1
expect(parsed[0]).to be_instance_of Icalendar::Calendar
end
it 'properly splits multi-valued lines' do
event = subject.parse.first.events.first
expect(event.geo).to eq [37.386013,-122.0829322]
end
it 'saves params' do
event = subject.parse.first.events.first
expect(event.dtstart.ical_params).to eq('tzid' => ['US-Mountain'])
end
end
describe 'missing date value parameter' do
let(:fn) { 'single_event_bad_dtstart.ics' }
it 'falls back to date type for dtstart' do
event = subject.parse.first.events.first
expect(event.dtstart).to be_kind_of Icalendar::Values::Date
end
end
end
|