amr_google_calendar 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,33 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <entry xmlns="http://www.w3.org/2005/Atom" xmlns:gCal="http://schemas.google.com/gCal/2005" xmlns:gd="http://schemas.google.com/g/2005">
3
+ <id>http://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio</id>
4
+ <published>2010-04-22T16:05:29.000Z</published>
5
+ <updated>2010-05-01T05:14:18.000Z</updated>
6
+ <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
7
+ <title type="text">Test</title>
8
+ <content type="text"/>
9
+ <link rel="alternate" type="text/html" href="https://www.google.com/calendar/event?eid=b2o2Zm1wYXVsYnZrOW91b2owbGo0djZoaW8gc3RldmUuemljaEBt" title="alternate"/>
10
+ <link rel="self" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio"/>
11
+ <link rel="edit" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio/63408374058"/>
12
+ <author>
13
+ <name>Some Guy</name>
14
+ <email>some.guy@gmail.com</email>
15
+ </author>
16
+ <gd:comments>
17
+ <gd:feedLink href="https://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio/comments"/>
18
+ </gd:comments>
19
+ <gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
20
+ <gd:where valueString=""/>
21
+ <gd:who email="some.guy@gmail.com" rel="http://schemas.google.com/g/2005#event.organizer" valueString="some.guy@gmail.com"/>
22
+ <gd:when endTime="2010-04-09" startTime="2010-04-08">
23
+ <gd:reminder method="alert" minutes="10"/>
24
+ </gd:when>
25
+ <gd:transparency value="http://schemas.google.com/g/2005#event.transparent"/>
26
+ <gd:visibility value="http://schemas.google.com/g/2005#event.default"/>
27
+ <gCal:anyoneCanAddSelf value="false"/>
28
+ <gCal:guestsCanInviteOthers value="true"/>
29
+ <gCal:guestsCanModify value="false"/>
30
+ <gCal:guestsCanSeeGuests value="true"/>
31
+ <gCal:sequence value="0"/>
32
+ <gCal:uid value="oj6fmpaulbvk9ouoj0lj4v6hio@google.com"/>
33
+ </entry>
@@ -0,0 +1,89 @@
1
+ <?xml version='1.0' encoding='utf-8'?>
2
+ <feed xmlns='http://www.w3.org/2005/Atom'
3
+ xmlns:openSearch='http://a9.com/-/spec/opensearch/1.1/'
4
+ xmlns:gCal='http://schemas.google.com/gCal/2005'
5
+ xmlns:gd='http://schemas.google.com/g/2005'
6
+ gd:etag='W/"CkYFSHg-fyp7ImA9WxRVGUo."'>
7
+ <id>http://www.google.com/calendar/feeds/default/allcalendars/full</id>
8
+ <updated>2008-11-18T01:01:59.657Z</updated>
9
+ <title>Coach's Calendar List</title>
10
+ <link rel='alternate' type='text/html'
11
+ href='https://www.google.com/calendar/render' />
12
+ <link rel='http://schemas.google.com/g/2005#feed'
13
+ type='application/atom+xml'
14
+ href='https://www.google.com/calendar/feeds/default/allcalendars/full' />
15
+ <link rel='http://schemas.google.com/g/2005#post'
16
+ type='application/atom+xml'
17
+ href='https://www.google.com/calendar/feeds/default/allcalendars/full' />
18
+ <link rel='self' type='application/atom+xml'
19
+ href='https://www.google.com/calendar/feeds/default/allcalendars/full' />
20
+ <author>
21
+ <name>Coach</name>
22
+ <email>user@gmail.com</email>
23
+ </author>
24
+ <generator version='1.0' uri='http://www.google.com/calendar'>Google Calendar</generator>
25
+ <openSearch:startIndex>1</openSearch:startIndex>
26
+ <entry gd:etag='W/"DU4ERH47eCp7ImA9WxRVEkQ."'>
27
+ <id>http://www.google.com/calendar/feeds/default/allcalendars/full/user%40gmail.com</id>
28
+ <published>2007-07-11T22:10:30.257Z</published>
29
+ <updated>2007-07-11T21:46:35.000Z</updated>
30
+ <title>My Primary Calendar</title>
31
+ <summary type='text'>A primary calendar is created by default for each Google Calendar user.</summary>
32
+ <link rel='alternate' type='application/atom+xml' href='https://www.google.com/calendar/feeds/user%40gmail.com/private/full' />
33
+ <link rel='http://schemas.google.com/gCal/2005#eventFeed' type='application/atom+xml' href='https://www.google.com/calendar/feeds/user%40gmail.com/private/full' />
34
+ <link rel='http://schemas.google.com/acl/2007#accessControlList' type='application/atom+xml' href='https://www.google.com/calendar/feeds/user%40gmail.com/acl/full' />
35
+ <link rel='self' type='application/atom+xml' href='https://www.google.com/calendar/feeds/default/allcalendars/full/user%40gmail.com' />
36
+ <link rel='edit' type='application/atom+xml' href='https://www.google.com/calendar/feeds/default/allcalendars/full/user%40gmail.com' />
37
+ <author>
38
+ <name>Coach</name>
39
+ <email>user@gmail.com</email>
40
+ </author>
41
+ <gCal:timezone value='America/Los_Angeles' />
42
+ <gCal:hidden value='false' />
43
+ <gCal:color value='#2952A3' />
44
+ <gCal:selected value='true' />
45
+ <gCal:accesslevel value='owner' />
46
+ <gd:where valueString='Mountain View' />
47
+ </entry>
48
+ <entry gd:etag='W/"Ck4GRH4-eSp7ImA9WxRVGUo."'>
49
+ <id>http://www.google.com/calendar/feeds/default/allcalendars/full/rf1c66uld6dgk2t5lh43svev6g%40group.calendar.google.com</id>
50
+ <published>2007-07-11T22:10:30.258Z</published>
51
+ <updated>2007-07-11T21:50:15.000Z</updated>
52
+ <title>Little Giants</title>
53
+ <summary type='text'>This calendar contains practice times and this season's Little League game schedule. Go Little Giants!</summary>
54
+ <link rel='alternate' type='application/atom+xml' href='https://www.google.com/calendar/feeds/rf1c66uld6dgk2t5lh43svev6g%40group.calendar.google.com/private/full'/>
55
+ <link rel='http://schemas.google.com/gCal/2005#eventFeed' type='application/atom+xml' href='https://www.google.com/calendar/feeds/rf1c66uld6dgk2t5lh43svev6g%40group.calendar.google.com/private/full'/>
56
+ <link rel='http://schemas.google.com/acl/2007#accessControlList' type='application/atom+xml' href='https://www.google.com/calendar/feeds/rf1c66uld6dgk2t5lh43svev6g%40group.calendar.google.com/acl/full'/>
57
+ <link rel='self' type='application/atom+xml' href='https://www.google.com/calendar/feeds/default/allcalendars/full/rf1c66uld6dgk2t5lh43svev6g%40group.calendar.google.com'/>
58
+ <link rel='edit' type='application/atom+xml' href='https://www.google.com/calendar/feeds/default/allcalendars/full/rf1c66uld6dgk2t5lh43svev6g%40group.calendar.google.com'/>
59
+ <author>
60
+ <name>Little Giants</name>
61
+ </author>
62
+ <gCal:timezone value='America/Los_Angeles' />
63
+ <gCal:hidden value='false' />
64
+ <gCal:color value='#5A6986' />
65
+ <gCal:selected value='false' />
66
+ <gCal:accesslevel value='owner' />
67
+ <gd:where valueString='San Francisco' />
68
+ </entry>
69
+ <entry gd:etag='W/"C0cEQnkyeip7ImA9WxRVGUo."'>
70
+ <id>http://www.google.com/calendar/feeds/default/allcalendars/full/c4o4i7m2lbamc4k26sc2vokh5g%40group.calendar.google.com</id>
71
+ <published>2007-07-11T22:10:30.297Z</published>
72
+ <updated>2007-06-05T09:38:50.000Z</updated>
73
+ <title>Google Doodles</title>
74
+ <summary type='text'/>
75
+ <link rel='alternate' type='application/atom+xml' href='https://www.google.com/calendar/feeds/c4o4i7m2lbamc4k26sc2vokh5g%40group.calendar.google.com/private/full'/>
76
+ <link rel='http://schemas.google.com/gCal/2005#eventFeed' type='application/atom+xml' href='https://www.google.com/calendar/feeds/c4o4i7m2lbamc4k26sc2vokh5g%40group.calendar.google.com/private/full'/>
77
+ <link rel='self' type='application/atom+xml' href='https://www.google.com/calendar/feeds/default/allcalendars/full/c4o4i7m2lbamc4k26sc2vokh5g%40group.calendar.google.com'/>
78
+ <link rel='edit' type='application/atom+xml' href='https://www.google.com/calendar/feeds/default/allcalendars/full/c4o4i7m2lbamc4k26sc2vokh5g%40group.calendar.google.com'/>
79
+ <author>
80
+ <name>Google Doodles</name>
81
+ </author>
82
+ <gCal:timezone value='Etc/GMT' />
83
+ <gCal:hidden value='false' />
84
+ <gCal:color value='#5229A3' />
85
+ <gCal:selected value='false' />
86
+ <gCal:accesslevel value='read' />
87
+ <gd:where valueString='' />
88
+ </entry>
89
+ </feed>
@@ -0,0 +1,55 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:gCal="http://schemas.google.com/gCal/2005" xmlns:gd="http://schemas.google.com/g/2005">
3
+ <id>http://www.google.com/calendar/feeds/default/private/full</id>
4
+ <updated>2010-12-10T07:09:25.000Z</updated>
5
+ <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
6
+ <title type="text">Some Guy</title>
7
+ <subtitle type="text">Some Guy</subtitle>
8
+ <link rel="alternate" type="text/html" href="https://www.google.com/calendar/embed?src=some.guy@gmail.com"/>
9
+ <link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full"/>
10
+ <link rel="http://schemas.google.com/g/2005#post" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full"/>
11
+ <link rel="http://schemas.google.com/g/2005#batch" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full/batch"/>
12
+ <link rel="self" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full?q=Test&amp;max-results=25"/>
13
+ <author>
14
+ <name>Some Guy</name>
15
+ <email>some.guy@gmail.com</email>
16
+ </author>
17
+ <generator version="1.0" uri="http://www.google.com/calendar">Google Calendar</generator>
18
+ <openSearch:totalResults>1</openSearch:totalResults>
19
+ <openSearch:startIndex>1</openSearch:startIndex>
20
+ <openSearch:itemsPerPage>25</openSearch:itemsPerPage>
21
+ <gCal:timezone value="America/Los_Angeles"/>
22
+ <gCal:timesCleaned value="0"/>
23
+ <entry>
24
+ <id>http://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio</id>
25
+ <published>2010-04-22T16:05:29.000Z</published>
26
+ <updated>2010-05-01T05:14:18.000Z</updated>
27
+ <category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/g/2005#event"/>
28
+ <title type="text">Test</title>
29
+ <content type="text"/>
30
+ <link rel="alternate" type="text/html" href="https://www.google.com/calendar/event?eid=b2o2Zm1wYXVsYnZrOW91b2owbGo0djZoaW8gc3RldmUuemljaEBt" title="alternate"/>
31
+ <link rel="self" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio"/>
32
+ <link rel="edit" type="application/atom+xml" href="https://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio/63408374058"/>
33
+ <author>
34
+ <name>Some Guy</name>
35
+ <email>some.guy@gmail.com</email>
36
+ </author>
37
+ <gd:comments>
38
+ <gd:feedLink href="https://www.google.com/calendar/feeds/default/private/full/oj6fmpaulbvk9ouoj0lj4v6hio/comments"/>
39
+ </gd:comments>
40
+ <gd:eventStatus value="http://schemas.google.com/g/2005#event.confirmed"/>
41
+ <gd:where valueString="At School"/>
42
+ <gd:who email="some.guy@gmail.com" rel="http://schemas.google.com/g/2005#event.organizer" valueString="some.guy@gmail.com"/>
43
+ <gd:when endTime="2010-04-09" startTime="2010-04-08">
44
+ <gd:reminder method="alert" minutes="10"/>
45
+ </gd:when>
46
+ <gd:transparency value="http://schemas.google.com/g/2005#event.transparent"/>
47
+ <gd:visibility value="http://schemas.google.com/g/2005#event.default"/>
48
+ <gCal:anyoneCanAddSelf value="false"/>
49
+ <gCal:guestsCanInviteOthers value="true"/>
50
+ <gCal:guestsCanModify value="false"/>
51
+ <gCal:guestsCanSeeGuests value="true"/>
52
+ <gCal:sequence value="0"/>
53
+ <gCal:uid value="oj6fmpaulbvk9ouoj0lj4v6hio@google.com"/>
54
+ </entry>
55
+ </feed>
@@ -0,0 +1,3 @@
1
+ SID=DQAAANQAAADZMefRbeG9x_P2llJUjewWWasEqC2mubuTSSjH414IJY-TTJF9voB3ZS80C9wFF68jKlpeUwL-9Pss9bk0_yNPCYtvTcx54L6rANjU1Go58r1X0B8RFatiA3Ak7S1zKxaUhfAB48dYoh-swUthjv_Ts8b7uCGUzfmOcKRGdQDy0-7Bdpy6r7cwVP68FPbA3EadPUrQGKKW-M4GXcB8iqymYNAL8utiGlAPtNFIM6It6uVInOiO0-24_pSYM1VxVJ2gBXa3lZevcLGObFHMQkka9Djrs2-d5OCoryjQo7RRFcxBxzZJqmwE
2
+ LSID=DQAAANUAAACgKc7kL-UwiEIsHKB-Rfd3cTPzWCav_-SzJy6e5IviYfruIvtswkDXxzSJ-rv-YmCOC-J0YO3ngnkmQoTnCJUjewWWasBIiO4bnKkk4K8IZdO8pBOHxpGuXBnKER4jaC7DwcQuVlEypBSFddj-s1mil8EQRUIR5SyRsyTbjS2uiO2slQ4jWyxGlds-s4b7DC8c7oMHuVjxrTtE_E9tZeIu4qXOb8QE1dwJGsaNWii7ioH5HVNuKMe0BjkKS5m7rymv4HhMnlN7mw09NJp1AMU9sfeiJ6kH5QVQuVxoAaA7rqm579I0pdQ
3
+ Auth=DQAAANUAAACgKc7kL-UwiEIsHKB-Rfd3cTPzWCav_-SzJy6e5IviYfruIvtswkDXxzSJ-rv-YmCOC-J0YO3ngnkmQoTnCJUjewWWasBIiO4bnKkk4K8IZdO8pBOHxpGuXBnKER4jaC7DwcQuVlEycRu6P375BUUgR1HNa3cxom45s1clzRKy9h4M4PZ2bO9ejr1qn5IkIUBuMmzvOJuDgIzm1V6YCZ_tErZ4WGq3u0tIm_VdDMn-rWEosH8OPfAp8BYShvAQy9cFSKYY1co8M0WJBbuoNlb52DnFtnUxw1UXW9d0xJ8bnSRkIUiDiMA')
@@ -0,0 +1,268 @@
1
+ require 'helper'
2
+
3
+ class TestGoogleCalendar < Test::Unit::TestCase
4
+ include Google
5
+
6
+ context "Connected" do
7
+
8
+ setup do
9
+ @http_mock = mock('Net::HTTPResponse')
10
+ @http_mock.stubs(:code => '200', :kind_of? => false, :message => "OK")
11
+ @http_mock.stubs(:kind_of?).with(Net::HTTPSuccess).returns(true)
12
+ @http_mock.stubs(:body).returns(get_mock_body('successful_login.txt'))
13
+ @http_request_mock = mock('Net::HTTPS')
14
+ @http_request_mock.stubs(:set_form_data => '', :request => @http_mock)
15
+
16
+ Net::HTTPS.stubs(:new).returns(@http_request_mock)
17
+ end
18
+
19
+ context "Login" do
20
+
21
+ should "login properly" do
22
+ assert_nothing_thrown do
23
+ Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret')
24
+ end
25
+ end
26
+
27
+ should "catch login with invalid credentials" do
28
+ @http_mock.stubs(:kind_of?).with(Net::HTTPForbidden).returns(true)
29
+ @http_mock.stubs(:body).returns('Error=BadAuthentication')
30
+ assert_raise(HTTPAuthorizationFailed) do
31
+ Calendar.new(:username => 'some.one@gmail.com', :password => 'wrong-password')
32
+ end
33
+ end
34
+
35
+ should "login properly with an app_name" do
36
+ assert_nothing_thrown do
37
+ Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret',
38
+ :app_name => 'northworld.com-googlecalendar-integration'
39
+ )
40
+ end
41
+ end
42
+
43
+ should "catch login with invalid app_name" do
44
+ @http_mock.stubs(:kind_of?).with(Net::HTTPForbidden).returns(true)
45
+ @http_mock.stubs(:body).returns('Error=BadAuthentication')
46
+ assert_raise(HTTPAuthorizationFailed) do
47
+ Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret',
48
+ :app_name => 'northworld.com-silly-cal'
49
+ )
50
+ end
51
+ end
52
+
53
+ should "login properly with an auth_url" do
54
+ assert_nothing_thrown do
55
+ Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret',
56
+ :auth_url => "https://www.google.com/accounts/ClientLogin"
57
+ )
58
+ end
59
+ end
60
+
61
+ should "catch login with invalid auth_url" do
62
+ @http_mock.stubs(:kind_of?).with(Net::HTTPForbidden).returns(true)
63
+ @http_mock.stubs(:body).returns('Error=BadAuthentication')
64
+ assert_raise(HTTPAuthorizationFailed) do
65
+ Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret',
66
+ :auth_url => "https://www.google.com/accounts/ClientLogin/waffles"
67
+ )
68
+ end
69
+ end
70
+
71
+ should "login properly with a calendar" do
72
+ assert_nothing_thrown do
73
+ cal = Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret',
74
+ :calendar => "Little Giants")
75
+
76
+ #mock calendar list request
77
+ calendar_uri = mock("get calendar uri")
78
+ Addressable::URI.expects(:parse).with("https://www.google.com/calendar/feeds/default/allcalendars/full").once.returns(calendar_uri)
79
+ Connection.any_instance.expects(:send).with(calendar_uri, :get).once.returns(mock("response", :body => get_mock_body('list_calendars.xml')))
80
+
81
+ #mock events list request
82
+ events_uri = mock("get events uri")
83
+ Addressable::URI.expects(:parse).with("https://www.google.com/calendar/feeds/rf1c66uld6dgk2t5lh43svev6g%40group.calendar.google.com/private/full").once.returns(events_uri)
84
+ Connection.any_instance.expects(:send).with(events_uri, :get).once.returns(mock("response", :body => get_mock_body('events.xml')))
85
+
86
+ cal.events
87
+ end
88
+ end
89
+
90
+ should "catch login with invalid calendar" do
91
+
92
+ assert_raise(InvalidCalendar) do
93
+ cal = Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret',
94
+ :calendar => "invalid calendar")
95
+
96
+ #mock calendar list request
97
+ calendar_uri = mock("get calendar uri")
98
+ Addressable::URI.expects(:parse).with("https://www.google.com/calendar/feeds/default/allcalendars/full").once.returns(calendar_uri)
99
+ Connection.any_instance.expects(:send).with(calendar_uri, :get).once.returns(mock("response", :body => get_mock_body('list_calendars.xml')))
100
+
101
+ cal.events
102
+ end
103
+ end
104
+
105
+ end # login context
106
+
107
+ context "Logged on" do
108
+ setup do
109
+ @calendar = Calendar.new(:username => 'some.one@gmail.com', :password => 'super-secret')
110
+ end
111
+
112
+ should "reload connection" do
113
+ old_connection = @calendar.connection
114
+ assert_not_equal old_connection, @calendar.reload.connection
115
+ end
116
+
117
+ should "find all events" do
118
+ @http_mock.stubs(:body).returns( get_mock_body("events.xml") )
119
+ assert_equal @calendar.events.length, 3
120
+ end
121
+
122
+ should "query events" do
123
+ @http_mock.stubs(:body).returns( get_mock_body("query_events.xml") )
124
+ event = @calendar.find_events('Test&gsessionid=12345')
125
+ assert_equal event.title, 'Test'
126
+ end
127
+
128
+ should "find events in range" do
129
+ start_min = DateTime.new(2011, 2, 1, 11, 1, 1)
130
+ start_max = DateTime.new(2011, 2, 28, 23, 59, 59)
131
+ @calendar.expects(:event_lookup).with('?start-min=2011-02-01T11:01:01&start-max=2011-02-28T23:59:59&recurrence-expansion-start=2011-02-01T11:01:01&recurrence-expansion-end=2011-02-28T23:59:59')
132
+ events = @calendar.find_events_in_range(start_min, start_max)
133
+ end
134
+
135
+ should "find an event by id" do
136
+ @http_mock.stubs(:body).returns( get_mock_body("find_event_by_id.xml") )
137
+ event = @calendar.find_event_by_id('oj6fmpaulbvk9ouoj0lj4v6hio')
138
+ assert_equal event.id, 'oj6fmpaulbvk9ouoj0lj4v6hio'
139
+ end
140
+
141
+ should "throw NotFound with invalid event id" do
142
+ @http_mock.stubs(:kind_of?).with(Net::HTTPNotFound).returns(true)
143
+ assert_equal @calendar.find_event_by_id('1234'), nil
144
+ end
145
+
146
+ should "create an event with block" do
147
+ @http_mock.stubs(:body).returns( get_mock_body("create_event.xml") )
148
+
149
+ event = @calendar.create_event do |e|
150
+ e.title = 'New Event'
151
+ e.start_time = Time.now + (60 * 60)
152
+ e.end_time = Time.now + (60 * 60 * 2)
153
+ e.content = "A new event"
154
+ e.where = "Joe's House"
155
+ end
156
+
157
+ assert_equal event.title, 'New Event'
158
+ end
159
+
160
+ should "create a quickadd event" do
161
+ @http_mock.stubs(:body).returns( get_mock_body("create_quickadd_event.xml") )
162
+
163
+ event = @calendar.create_event do |e|
164
+ e.content = "movie tomorrow 23:00 at AMC Van Ness"
165
+ e.quickadd = true
166
+ end
167
+
168
+ assert_equal event.content, "movie tomorrow 23:00 at AMC Van Ness"
169
+ end
170
+
171
+ should "format to_s properly" do
172
+ @http_mock.stubs(:body).returns( get_mock_body("query_events.xml") )
173
+ event = @calendar.find_events('Test')
174
+ assert_equal event.to_s, "Test (oj6fmpaulbvk9ouoj0lj4v6hio)\n\t2010-04-08\n\t2010-04-09\n\tAt School\n\t"
175
+ end
176
+
177
+ should "update an event by id" do
178
+ @http_mock.stubs(:body).returns( get_mock_body("find_event_by_id.xml") )
179
+
180
+ event = @calendar.find_or_create_event_by_id('oj6fmpaulbvk9ouoj0lj4v6hio') do |e|
181
+ e.title = 'New Event Update'
182
+ end
183
+
184
+ assert_equal event.title, 'New Event Update'
185
+ end
186
+
187
+ should "delete an event" do
188
+ @http_mock.stubs(:body).returns( get_mock_body("create_event.xml") )
189
+
190
+ event = @calendar.create_event do |e|
191
+ e.title = 'Delete Me'
192
+ end
193
+
194
+ assert_equal event.id, 'b1vq6rj4r4mg85kcickc7iomb0'
195
+
196
+ @http_mock.stubs(:body).returns("")
197
+ event.delete
198
+ assert_equal event.id, nil
199
+ end
200
+
201
+ should "not redirect forever" do
202
+ @http_mock.stubs(:kind_of?).with(Net::HTTPRedirection).returns(true)
203
+ @http_mock.stubs(:[]).with('location').returns('https://www.google.com')
204
+ assert_raise(HTTPTooManyRedirections) do
205
+ @calendar.events
206
+ end
207
+ end
208
+
209
+ should "throw exception on bad request" do
210
+ @http_mock.stubs(:kind_of?).with(Net::HTTPBadRequest).returns(true)
211
+ assert_raise(HTTPRequestFailed) do
212
+ @calendar.events
213
+ end
214
+ end
215
+
216
+ end # Logged on context
217
+
218
+ end # Connected context
219
+
220
+ context "Event instance methods" do
221
+ context "#all_day?" do
222
+ context "when the event is 24 hours long or more" do
223
+ should "be true" do
224
+ @event = Event.new(:start_time => "2012-03-31", :end_time => "2012-04-01")
225
+ assert @event.all_day?
226
+ end
227
+ end
228
+ context "when the event is not an all-day event" do
229
+ should "be false" do
230
+ @event = Event.new(:start_time => "2012-03-27T10:00:00.000-07:00", :end_time => "2012-03-27T10:30:00.000-07:00")
231
+ assert !@event.all_day?
232
+ end
233
+ end
234
+ end
235
+
236
+ context "#all_day=" do
237
+ context "sets the start and end time to the appropriate values for an all day event on that day" do
238
+ should "set the start time" do
239
+ @event = Event.new :all_day => Time.parse("2012-05-02 12:24")
240
+ assert_equal @event.start_time, "2012-05-02"
241
+ end
242
+ should "set the end time" do
243
+ @event = Event.new :all_day => Time.parse("2012-05-02 12:24")
244
+ assert_equal @event.end_time, "2012-05-03"
245
+ end
246
+ should "be able to handle strings" do
247
+ @event = Event.new :all_day => "2012-05-02 12:24"
248
+ assert_equal @event.start_time, "2012-05-02"
249
+ assert_equal @event.end_time, "2012-05-03"
250
+ end
251
+ end
252
+ end
253
+ end
254
+
255
+ def test_https_extension
256
+ assert_nothing_thrown do
257
+ uri = Addressable::URI.parse('https://www.google.com')
258
+ Net::HTTPS.new(uri.host, uri.port)
259
+ end
260
+ end
261
+
262
+ protected
263
+
264
+ def get_mock_body(name)
265
+ File.open(@@mock_path + '/' + name).read
266
+ end
267
+
268
+ end