jam-cloud/ruby/spec/jam_ruby/calendar_manager_spec.rb

86 lines
2.6 KiB
Ruby
Raw Normal View History

Merge feature/calendaring branch: commit 8023d6481cbadd52e58b9a4342ac7636ce1807e3 VRFS-3276 : Hook calendar creation into user controller API. Add test to verify. commit 3a35002a46f870e2c490b88b3187e0b1569494fd VRFS-3276 : Calendar cleanup job * Add cleanup method to calendar manager * Create a daily job. * Add calendar cleanup to that job. * Add CRON entry * Daily job/ calendar cleanup test cases * Fix calendar manager spec for new required attribute commit 3ff5910f1f019ae8bcb5afe72a31f1d38bb7d7a3 VRFS-3276 : Add a delete-calendar directive when RSVP is canceled. VRFS-3276 : Include path to partial. This fails depending on the method used to start the web server. commit d2441cbf57e50895ac3b40534873c5d529cb3c4f VRFS-3276 : Test new calendar features. Use icalendar gem in test mode only to more deeply verify calendar in strict mode. commit 9ac272a0fb1e58d8cf9f02e7a0e04caada41f659 VRFS-3276 : Calendar manager updates to include manual calendars. Some refactoring to keep common stuff in one place. commit b5d0c758f0dcae41a5f24635e9da9ce6eda56670 VRFS-3276 : Schema, model updates and new calendar model. commit 20472b6b26c88c04edb9bc698e0c06c549e12eb5 VRFS-3276 : Change initial submit behavior of RSVP dialog to display calendar info. The user can then close the dialog after this prompt. commit 77c99103d0221f20ea342169821b90fa987ecf93 VRFS-3276 : Calendar feed markup and styling. Included as partial. commit e632f48600ae23b5f742773310b2a4ac16ae4ee8 VRFS-3276 : Routes and controller implementation of user calendar ICS feed, which uses calendar manager. commit 21fd80a188eae771a65333566b804ade795a1e8c VRFS-3276 : Initial tests for calendar manager commit 92a2524c65abf7b540f9d50049a1b760a5a9927f VRFS-3276 : Calendar manager * Streamline logic * Enable recurring sessions through rrule * Implement method to create ics feed for user * Extract a type-safe scheduled duration method on music_session for external and internal use. commit b71ad3a4cdd943eb84748abaa85fec263b9af468 VRFS-3276 : Include calendar manager commit f8eaafd03647613dafec9f9422282f8613d08e9a VRFS-3276 : Calendar Manager - initial checkin * Create ICS events given individual parameters * Create calendar from music session * Also will create ICS “delete” events
2015-07-06 20:34:27 +00:00
require 'spec_helper'
require 'icalendar'
describe CalendarManager do
CALENDAR_NAME="Test Cal"
before :all do
@genre1 = FactoryGirl.create(:genre)
@calendar_manager = JamRuby::CalendarManager.new
# Time resolution is seconds:
@start = Time.at(Time.now.utc.to_i)
@stop =(@start+1.hours)
end
before(:each) do
end
describe "with music sessions" do
before :all do
@creator = FactoryGirl.create(:user)
@music_session = FactoryGirl.create(:music_session, :creator => @creator, :description => CALENDAR_NAME, :genre => @genre1, :scheduled_start=>@start, :scheduled_duration=>3600)
@music_session.reload
end
it "validator detects bad calendar" do
lambda{verify_ical("Bad medicine calendar")}
.should raise_error(RuntimeError)
end
it "can create calendar feed" do
ics = @calendar_manager.create_ics_feed(@creator)
# Basic format checking...there are some online tools that
# check a lot more, but no ruby libs that I could find:
lines = ics.split("\r\n")
lines.should have(12).items
lines.first.should eq("BEGIN:VCALENDAR")
lines.last.should eq("END:VCALENDAR")
lines[-2].should eq("END:VEVENT")
verify_ical(ics)
end
end
describe "with manual calendars" do
before :all do
@creator = FactoryGirl.create(:user)
@creator.calendars<<Calendar.new({:name=>CALENDAR_NAME, :description=>"This is a test", :start_at=>(@start), :end_at=>@stop, :trigger_delete=>false, :target_uid=>"2112"})
end
it "can create calendar feed" do
#pending "foobar"
ics = @calendar_manager.create_ics_feed(@creator)
# Basic format checking...there are some online tools that
# check a lot more, but no ruby libs that I could find:
lines = ics.split("\r\n")
lines.should have(12).items
lines.first.should eq("BEGIN:VCALENDAR")
lines.last.should eq("END:VCALENDAR")
lines[-2].should eq("END:VEVENT")
verify_ical(ics)
end
end
def verify_ical(ics)
strict_parser = Icalendar::Parser.new(ics, true)
cals = strict_parser.parse
cals.should_not be_nil
cals.should have(1).items
cal = cals.first
cal.should_not be_nil
cal.events.should have(1).items
event = cal.events.first
event.should_not be_nil
event.summary.should eq("JamKazam Session #{CALENDAR_NAME}")
event.dtstart.to_i.should_not be_nil
event.dtend.to_i.should_not be_nil
(event.dtstart).to_time.utc.to_i.should eq(@start.to_i)
#(event.dtend).to_time.utc.to_i.should eq(@stop.to_i) # can't get it to work
Merge feature/calendaring branch: commit 8023d6481cbadd52e58b9a4342ac7636ce1807e3 VRFS-3276 : Hook calendar creation into user controller API. Add test to verify. commit 3a35002a46f870e2c490b88b3187e0b1569494fd VRFS-3276 : Calendar cleanup job * Add cleanup method to calendar manager * Create a daily job. * Add calendar cleanup to that job. * Add CRON entry * Daily job/ calendar cleanup test cases * Fix calendar manager spec for new required attribute commit 3ff5910f1f019ae8bcb5afe72a31f1d38bb7d7a3 VRFS-3276 : Add a delete-calendar directive when RSVP is canceled. VRFS-3276 : Include path to partial. This fails depending on the method used to start the web server. commit d2441cbf57e50895ac3b40534873c5d529cb3c4f VRFS-3276 : Test new calendar features. Use icalendar gem in test mode only to more deeply verify calendar in strict mode. commit 9ac272a0fb1e58d8cf9f02e7a0e04caada41f659 VRFS-3276 : Calendar manager updates to include manual calendars. Some refactoring to keep common stuff in one place. commit b5d0c758f0dcae41a5f24635e9da9ce6eda56670 VRFS-3276 : Schema, model updates and new calendar model. commit 20472b6b26c88c04edb9bc698e0c06c549e12eb5 VRFS-3276 : Change initial submit behavior of RSVP dialog to display calendar info. The user can then close the dialog after this prompt. commit 77c99103d0221f20ea342169821b90fa987ecf93 VRFS-3276 : Calendar feed markup and styling. Included as partial. commit e632f48600ae23b5f742773310b2a4ac16ae4ee8 VRFS-3276 : Routes and controller implementation of user calendar ICS feed, which uses calendar manager. commit 21fd80a188eae771a65333566b804ade795a1e8c VRFS-3276 : Initial tests for calendar manager commit 92a2524c65abf7b540f9d50049a1b760a5a9927f VRFS-3276 : Calendar manager * Streamline logic * Enable recurring sessions through rrule * Implement method to create ics feed for user * Extract a type-safe scheduled duration method on music_session for external and internal use. commit b71ad3a4cdd943eb84748abaa85fec263b9af468 VRFS-3276 : Include calendar manager commit f8eaafd03647613dafec9f9422282f8613d08e9a VRFS-3276 : Calendar Manager - initial checkin * Create ICS events given individual parameters * Create calendar from music session * Also will create ICS “delete” events
2015-07-06 20:34:27 +00:00
end
end