Skip to content

Commit 24ce2aa

Browse files
committed
add exrule tests
1 parent 0881ed9 commit 24ce2aa

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

spec/examples/ice_cube_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@
254254
schedule.rrules.should == rules
255255
end
256256

257+
it 'can retrieve exrules from a schedule' do
258+
schedule = IceCube::Schedule.new(Time.now)
259+
rules = [IceCube::Rule.daily, IceCube::Rule.monthly, IceCube::Rule.yearly]
260+
rules.each { |r| schedule.add_exception_rule(r) }
261+
# pull the rules back out of the schedule and compare
262+
schedule.exrules.should == rules
263+
end
264+
257265
it 'can retrieve recurrence times from a schedule' do
258266
schedule = IceCube::Schedule.new(Time.now)
259267
times = [Time.now, Time.now + 5, Time.now + 10]
@@ -569,6 +577,14 @@
569577
schedule.rrules.should == [daily, monthly]
570578
end
571579

580+
it 'should have some convenient alias for exrules' do
581+
schedule = IceCube::Schedule.new(Time.now)
582+
daily = IceCube::Rule.daily; monthly = IceCube::Rule.monthly
583+
schedule.add_exception_rule daily
584+
schedule.exrule monthly
585+
schedule.exrules.should == [daily, monthly]
586+
end
587+
572588
it 'should have some convenient alias for recurrence_times' do
573589
schedule = IceCube::Schedule.new(Time.now)
574590
schedule.add_recurrence_time Time.local(2010, 8, 13)
@@ -583,6 +599,14 @@
583599
schedule.extimes.should == [Time.local(2010, 8, 13), Time.local(2010, 8, 14)]
584600
end
585601

602+
it 'should be able to have a rule and an exrule' do
603+
schedule = IceCube::Schedule.new(Time.local(2010, 8, 27, 10))
604+
schedule.rrule IceCube::Rule.daily
605+
schedule.exrule IceCube::Rule.daily.day(:friday)
606+
schedule.occurs_on?(Date.new(2010, 8, 27)).should be_false
607+
schedule.occurs_on?(Date.new(2010, 8, 28)).should be_true
608+
end
609+
586610
it 'should always generate the correct number of days for .first' do
587611
s = IceCube::Schedule.new(Time.zone.parse('1-1-1985'))
588612
r = IceCube::Rule.weekly(3).day(:monday, :wednesday, :friday)

spec/examples/to_ical_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,27 @@
126126
schedule.to_ical.should == expectation
127127
end
128128

129+
it 'should be able to serialize a schedule with one exrule' do
130+
Time.zone ='Pacific Time (US & Canada)'
131+
schedule = IceCube::Schedule.new(Time.zone.local(2010, 5, 10, 9, 0, 0))
132+
schedule.add_exception_rule IceCube::Rule.weekly
133+
# test equality
134+
expectation= "DTSTART;TZID=PDT:20100510T090000\n"
135+
expectation<< 'EXRULE:FREQ=WEEKLY'
136+
schedule.to_ical.should == expectation
137+
end
138+
139+
it 'should be able to serialize a schedule with multiple exrules' do
140+
Time.zone ='Eastern Time (US & Canada)'
141+
schedule = IceCube::Schedule.new(Time.zone.local(2010, 10, 20, 4, 30, 0))
142+
schedule.add_exception_rule IceCube::Rule.weekly.day_of_week(:monday => [2, -1])
143+
schedule.add_exception_rule IceCube::Rule.hourly
144+
expectation = "DTSTART;TZID=EDT:20101020T043000\n"
145+
expectation<< "EXRULE:FREQ=WEEKLY;BYDAY=2MO,-1MO\n"
146+
expectation<< "EXRULE:FREQ=HOURLY"
147+
schedule.to_ical.should == expectation
148+
end
149+
129150
it 'should be able to serialize a schedule with an rtime' do
130151
schedule = IceCube::Schedule.new(Time.utc(2010, 5, 10, 10, 0, 0))
131152
schedule.add_recurrence_time Time.utc(2010, 6, 20, 5, 0, 0)

0 commit comments

Comments
 (0)