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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
require 'spec_helper'
describe Icalendar do
describe 'single event round trip' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'single_event.ics') }
it 'will generate the same file as is parsed' do
ical = Icalendar::Calendar.parse(source).first.to_ical
expect(ical).to eq source
end
it 'array properties can be assigned to a new event' do
event = Icalendar::Event.new
parsed = Icalendar::Calendar.parse(source).first
event.rdate = parsed.events.first.rdate
expect(event.rdate.first).to be_kind_of Icalendar::Values::Array
expect(event.rdate.first.params_ical).to eq ";TZID=US-Mountain"
end
end
describe 'cleanly handle facebook organizers' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'single_event_bad_organizer.ics') }
let(:source_lowered_uri) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'single_event_organizer_parsed.ics') }
it 'will generate the same file as it parsed' do
ical = Icalendar::Calendar.parse(source).first.to_ical
source_equal = ical == source
# rbx-3 parses the organizer as a URI, which strips the space and lowercases everything after the first :
# this is correct behavior, according to the icalendar spec, so we're not fudging the parser to accomodate
# facebook not properly wrapping the CN param in dquotes
source_lowered_equal = ical == source_lowered_uri
expect(source_equal || source_lowered_equal).to be true
end
end
describe 'timezone round trip' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'timezone.ics') }
it 'will generate the same file as it parsed' do
ical = Icalendar::Calendar.parse(source).first.to_ical
expect(ical).to eq source
end
end
describe 'non-default values' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'nondefault_values.ics') }
subject { Icalendar::Calendar.parse(source).first.events.first }
it 'will set dtstart to Date' do
expect(subject.dtstart.value).to eq ::Date.new(2006, 12, 15)
end
it 'will set dtend to Date' do
expect(subject.dtend.value).to eq ::Date.new(2006, 12, 15)
end
it 'will output value param on dtstart' do
expect(subject.dtstart.to_ical(subject.class.default_property_types['dtstart'])).to match /^;VALUE=DATE:20061215$/
end
it 'will output value param on dtend' do
expect(subject.dtend.to_ical(subject.class.default_property_types['dtend'])).to match /^;VALUE=DATE:20061215$/
end
end
describe 'sorting daily events' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'two_day_events.ics') }
subject { Icalendar::Calendar.parse(source).first.events }
it 'sorts day events' do
events = subject.sort_by(&:dtstart)
expect(events.first.dtstart).to eq ::Date.new(2014, 7, 13)
expect(events.last.dtstart).to eq ::Date.new(2014, 7, 14)
end
end
describe 'sorting time events' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'two_time_events.ics') }
subject { Icalendar::Calendar.parse(source).first.events }
xit 'sorts time events by start time' do
events = subject.sort_by(&:dtstart)
expect(events.first.dtstart.to_datetime).to eq ::DateTime.new(2014, 7, 14, 9, 0, 0, '-4')
expect(events.last.dtstart.to_datetime).to eq ::DateTime.new(2014, 7, 14, 9, 1, 0, '-4')
expect(events.last.dtend.to_datetime).to eq ::DateTime.new(2014, 7, 14, 9, 59, 0, '-4')
end
xit 'sorts time events by end time' do
events = subject.sort_by(&:dtend)
expect(events.first.dtstart.to_datetime).to eq ::DateTime.new(2014, 7, 14, 9, 1, 0, '-4')
expect(events.first.dtend.to_datetime).to eq ::DateTime.new(2014, 7, 14, 9, 59, 0, '-4')
expect(events.last.dtstart.to_datetime).to eq ::DateTime.new(2014, 7, 14, 9, 0, 0, '-4')
end
end
describe 'sorting date / time events' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'two_date_time_events.ics') }
subject { Icalendar::Calendar.parse(source).first.events }
xit 'sorts time events' do
events = subject.sort_by(&:dtstart)
expect(events.first.dtstart.to_date).to eq ::Date.new(2014, 7, 14)
expect(events.last.dtstart.to_datetime).to eq ::DateTime.new(2014, 7, 14, 9, 0, 0, '-4')
end
end
describe 'non-standard values' do
if defined? File::NULL
before(:all) { Icalendar.logger = Icalendar::Logger.new File::NULL }
after(:all) { Icalendar.logger = nil }
end
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'nonstandard.ics') }
subject { Icalendar::Parser.new(source, strict) }
context 'strict parser' do
let(:strict) { true }
specify { expect { subject.parse }.to raise_error(NoMethodError) }
end
context 'lenient parser' do
let(:strict) { false }
specify { expect { subject.parse }.to_not raise_error }
context 'saves non-standard fields' do
let(:parsed) { subject.parse.first.events.first }
specify { expect(parsed.custom_property('customfield').first).to eq 'Not properly noted as custom with X- prefix.' }
specify { expect(parsed.custom_property('CUSTOMFIELD').first).to eq 'Not properly noted as custom with X- prefix.' }
end
it 'can output custom fields' do
ical = subject.parse.first.to_ical
expect(ical).to include 'CUSTOMFIELD:Not properly noted as custom with X- prefix.'
end
context 'custom components' do
let(:source) { File.read File.join(File.dirname(__FILE__), 'fixtures', 'custom_component.ics') }
it 'can output the custom component' do
ical = subject.parse.first.to_ical
expect(ical).to include 'BEGIN:X-EVENT-SERIES'
end
end
end
end
end
|