VRFS-3276 : Test new calendar features. Use icalendar gem in test mode only to more deeply verify calendar in strict mode.
This commit is contained in:
parent
9ac272a0fb
commit
d2441cbf57
|
|
@ -16,6 +16,3 @@ PLATFORMS
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
pg_migrate (= 0.1.13)
|
pg_migrate (= 0.1.13)
|
||||||
|
|
||||||
BUNDLED WITH
|
|
||||||
1.10.3
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ group :test do
|
||||||
gem 'rspec-prof'
|
gem 'rspec-prof'
|
||||||
gem 'time_difference'
|
gem 'time_difference'
|
||||||
gem 'byebug'
|
gem 'byebug'
|
||||||
|
gem 'icalendar'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Specify your gem's dependencies in jam_ruby.gemspec
|
# Specify your gem's dependencies in jam_ruby.gemspec
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,85 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
require 'icalendar'
|
||||||
|
|
||||||
describe CalendarManager do
|
describe CalendarManager do
|
||||||
|
CALENDAR_NAME="Test Cal"
|
||||||
|
|
||||||
before :all do
|
before :all do
|
||||||
genre1 = FactoryGirl.create(:genre)
|
@genre1 = FactoryGirl.create(:genre)
|
||||||
@creator = FactoryGirl.create(:user)
|
|
||||||
@music_session = FactoryGirl.create(:music_session, :creator => @creator, :description => "Hello Session", :genre => genre1)
|
|
||||||
@music_session.reload
|
|
||||||
@calendar_manager = JamRuby::CalendarManager.new
|
@calendar_manager = JamRuby::CalendarManager.new
|
||||||
|
|
||||||
|
# Time resolution is seconds:
|
||||||
|
@start = Time.at(Time.now.utc.to_i)
|
||||||
|
@stop =(@start+1.hours)
|
||||||
end
|
end
|
||||||
|
|
||||||
before(:each) do
|
before(:each) do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can create calendar feed for user" do
|
describe "with music sessions" do
|
||||||
ics = @calendar_manager.create_ics_feed(@creator)
|
before :all do
|
||||||
puts "ICS: #{ics}"
|
@creator = FactoryGirl.create(:user)
|
||||||
# Basic format checking...there are some online tools that
|
@music_session = FactoryGirl.create(:music_session, :creator => @creator, :description => CALENDAR_NAME, :genre => @genre1, :scheduled_start=>@start, :scheduled_duration=>3600)
|
||||||
# check a lot more, but no ruby libs that I could find:
|
@music_session.reload
|
||||||
lines = ics.split("\r\n")
|
end
|
||||||
lines.should have(11).items
|
|
||||||
lines.first.should eq("BEGIN:VCALENDAR")
|
it "validator detects bad calendar" do
|
||||||
lines.last.should eq("END:VCALENDAR")
|
lambda{verify_ical("Bad medicine calendar")}
|
||||||
lines[-2].should eq("END:VEVENT")
|
.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
|
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})
|
||||||
|
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)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue