gmail-api-ruby 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -4
- data/CHANGELOG.md +1 -1
- data/README.md +65 -11
- data/Rakefile +6 -9
- data/TODO.md +1 -2
- data/account.yml.example +5 -0
- data/gmail.gemspec +3 -2
- data/lib/gmail.rb +20 -14
- data/lib/gmail/api_resource.rb +0 -1
- data/lib/gmail/base/delete.rb +6 -2
- data/lib/gmail/base/list.rb +6 -2
- data/lib/gmail/draft.rb +6 -1
- data/lib/gmail/gmail_object.rb +11 -2
- data/lib/gmail/label.rb +2 -2
- data/lib/gmail/message.rb +23 -5
- data/lib/gmail/thread.rb +10 -4
- data/lib/gmail/version.rb +1 -1
- data/test/gmail/api_resource_test.rb +47 -0
- data/test/gmail/draft_test.rb +104 -0
- data/test/gmail/gmail_object_test.rb +45 -0
- data/test/gmail/label_test.rb +129 -0
- data/test/gmail/message_test.rb +266 -0
- data/test/gmail/thread_test.rb +184 -0
- data/test/gmail/util_test.rb +18 -0
- data/test/test_data.rb +175 -0
- data/test/test_helper.rb +33 -0
- metadata +45 -12
- data/.rspec +0 -2
@@ -0,0 +1,266 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# encoding: utf-8
|
3
|
+
require File.expand_path('../../test_helper', __FILE__)
|
4
|
+
|
5
|
+
module Gmail
|
6
|
+
class MessageTest < Test::Unit::TestCase
|
7
|
+
|
8
|
+
should "messages should be listable" do
|
9
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.list, parameters: {userId: "me"}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message_list))
|
10
|
+
list = Gmail::Message.all
|
11
|
+
assert_equal Array, list.class
|
12
|
+
assert_equal Gmail::Message, list[0].class
|
13
|
+
end
|
14
|
+
|
15
|
+
should "message should be retrievable by id" do
|
16
|
+
|
17
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.get, parameters: {userId: "me", id: test_message[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message))
|
18
|
+
t = Gmail::Message.get(test_message[:id])
|
19
|
+
assert_equal Gmail::Message, t.class
|
20
|
+
assert_equal test_message[:id], t.id
|
21
|
+
end
|
22
|
+
|
23
|
+
should "message construct should set some basics values" do
|
24
|
+
|
25
|
+
m = Gmail::Message.new(test_message)
|
26
|
+
["From", "To", "Cc", "Subject", "Bcc", "Date", "Message-ID", "References", "In-Reply-To", "Delivered-To"].each do |method|
|
27
|
+
assert_equal test_message[:payload][:headers].select{|h| h[:name].downcase == method.downcase}.first[:value], m.send(method.downcase.tr("-", "_"))
|
28
|
+
end
|
29
|
+
assert_not_nil m.text || m.body || m.html
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
should "message (with strange format) construct should set at least body, text or html" do
|
34
|
+
|
35
|
+
m = Gmail::Message.new(test_strange_message)
|
36
|
+
assert_not_nil m.text || m.body || m.html
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
should "Access thread from message" do
|
44
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.get, parameters: {userId: "me", id: test_message[:threadId]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_thread))
|
45
|
+
m = Gmail::Message.new(test_message)
|
46
|
+
t = m.thread
|
47
|
+
assert_equal test_message[:threadId], m.thread_id
|
48
|
+
assert_equal Gmail::Thread, t.class
|
49
|
+
end
|
50
|
+
|
51
|
+
should "message should be deletable" do
|
52
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.delete, parameters: {userId: "me", id: test_message[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(""))
|
53
|
+
t = Gmail::Message.new(test_message)
|
54
|
+
r = t.delete
|
55
|
+
assert r
|
56
|
+
end
|
57
|
+
|
58
|
+
should "message should be thrashable" do
|
59
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.trash, parameters: {userId: "me", id: test_message[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message))
|
60
|
+
t = Gmail::Message.new(test_message)
|
61
|
+
r = t.trash
|
62
|
+
assert_equal Gmail::Message, r.class
|
63
|
+
end
|
64
|
+
|
65
|
+
should "message should be unthrashable" do
|
66
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.untrash, parameters: {userId: "me", id: test_message[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message))
|
67
|
+
t = Gmail::Message.new(test_message)
|
68
|
+
r = t.untrash
|
69
|
+
assert_equal Gmail::Message, r.class
|
70
|
+
end
|
71
|
+
|
72
|
+
context "Modifying Labels" do
|
73
|
+
should "message should be starrable" do
|
74
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.modify, parameters: {userId: "me", id: test_message[:id]}, body_object: {addLabelIds: ["STARRED"], removeLabelIds: []} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
75
|
+
t = Gmail::Message.new(test_message)
|
76
|
+
r = t.star
|
77
|
+
assert_equal Gmail::Message, r.class
|
78
|
+
assert_not_equal t.object_id, r.object_id
|
79
|
+
|
80
|
+
r = t.star!
|
81
|
+
|
82
|
+
assert_equal t.object_id, r.object_id
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
should "message should be unstarrable" do
|
87
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.modify, parameters: {userId: "me", id: test_message[:id]}, body_object: {addLabelIds: [], removeLabelIds: ["STARRED"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
88
|
+
t = Gmail::Message.new(test_message)
|
89
|
+
r = t.unstar
|
90
|
+
assert_equal Gmail::Message, r.class
|
91
|
+
|
92
|
+
assert_not_equal t.object_id, r.object_id
|
93
|
+
|
94
|
+
r = t.unstar!
|
95
|
+
|
96
|
+
assert_equal t.object_id, r.object_id
|
97
|
+
end
|
98
|
+
|
99
|
+
should "message should be archivable" do
|
100
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.modify, parameters: {userId: "me", id: test_message[:id]}, body_object: {addLabelIds: [], removeLabelIds: ["INBOX"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
101
|
+
t = Gmail::Message.new(test_message)
|
102
|
+
r = t.archive
|
103
|
+
assert_equal Gmail::Message, r.class
|
104
|
+
assert_not_equal t.object_id, r.object_id
|
105
|
+
|
106
|
+
r = t.archive!
|
107
|
+
|
108
|
+
assert_equal t.object_id, r.object_id
|
109
|
+
end
|
110
|
+
|
111
|
+
should "message should be unarchivable" do
|
112
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.modify, parameters: {userId: "me", id: test_message[:id]}, body_object: {addLabelIds: ["INBOX"], removeLabelIds: []} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
113
|
+
t = Gmail::Message.new(test_message)
|
114
|
+
r = t.unarchive
|
115
|
+
assert_equal Gmail::Message, r.class
|
116
|
+
assert_not_equal t.object_id, r.object_id
|
117
|
+
|
118
|
+
r = t.unarchive!
|
119
|
+
|
120
|
+
assert_equal t.object_id, r.object_id
|
121
|
+
end
|
122
|
+
|
123
|
+
should "message should be markable as read" do
|
124
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.modify, parameters: {userId: "me", id: test_message[:id]}, body_object: {addLabelIds: [], removeLabelIds: ["UNREAD"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
125
|
+
t = Gmail::Message.new(test_message)
|
126
|
+
r = t.mark_as_read
|
127
|
+
assert_equal Gmail::Message, r.class
|
128
|
+
assert_not_equal t.object_id, r.object_id
|
129
|
+
|
130
|
+
r = t.mark_as_read!
|
131
|
+
|
132
|
+
assert_equal t.object_id, r.object_id
|
133
|
+
end
|
134
|
+
|
135
|
+
should "message should be markable as unread" do
|
136
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.modify, parameters: {userId: "me", id: test_message[:id]}, body_object: {addLabelIds: ["UNREAD"], removeLabelIds: []} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
137
|
+
t = Gmail::Message.new(test_message)
|
138
|
+
r = t.mark_as_unread
|
139
|
+
assert_equal Gmail::Message, r.class
|
140
|
+
assert_not_equal t.object_id, r.object_id
|
141
|
+
|
142
|
+
r = t.mark_as_unread!
|
143
|
+
|
144
|
+
assert_equal t.object_id, r.object_id
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
should "message label should be modifiable as wish" do
|
149
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.modify, parameters: {userId: "me", id: test_message[:id]}, body_object: {addLabelIds: ["UNREAD", "SOME COOL LABEL"], removeLabelIds: ["INBOX", "SOME NOT COOL LABEL"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
150
|
+
t = Gmail::Message.new(test_message)
|
151
|
+
r = t.modify ["UNREAD", "SOME COOL LABEL"], ["INBOX", "SOME NOT COOL LABEL"]
|
152
|
+
assert_equal Gmail::Message, r.class
|
153
|
+
assert_not_equal t.object_id, r.object_id
|
154
|
+
|
155
|
+
r = t.modify! ["UNREAD", "SOME COOL LABEL"], ["INBOX", "SOME NOT COOL LABEL"]
|
156
|
+
|
157
|
+
assert_equal t.object_id, r.object_id
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
|
162
|
+
|
163
|
+
should "Helpers should work" do
|
164
|
+
m = Gmail::Message.new test_message
|
165
|
+
assert_false m.sent?
|
166
|
+
assert_false m.inbox?
|
167
|
+
assert_false m.unread?
|
168
|
+
m = Gmail::Message.new test_inbox_message
|
169
|
+
assert_false m.sent?
|
170
|
+
assert m.inbox?
|
171
|
+
assert_false m.unread?
|
172
|
+
m = Gmail::Message.new test_sent_message
|
173
|
+
assert m.sent?
|
174
|
+
assert_false m.inbox?
|
175
|
+
assert_false m.unread?
|
176
|
+
m = Gmail::Message.new test_unread_message
|
177
|
+
assert_false m.sent?
|
178
|
+
assert_false m.inbox?
|
179
|
+
assert m.unread?
|
180
|
+
end
|
181
|
+
|
182
|
+
|
183
|
+
should "Message should be searcheable" do
|
184
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.list, parameters: {userId: "me", q: "from:(me) to:(you) subject:(subject) in:inbox before:2014/12/1 after:2014/11/1 test -{real}", labelIds:["UNREAD"]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message_list))
|
185
|
+
list = Gmail::Message.search(from:"me", to: "you", subject: "subject", in: "inbox", before: "2014/12/1", after: "2014/11/1", has_words: "test", has_not_words: "real", labelIds: ["UNREAD"])
|
186
|
+
assert_equal Array, list.class
|
187
|
+
assert_equal Gmail::Message, list[0].class
|
188
|
+
end
|
189
|
+
|
190
|
+
should "Message should construct RAW string correctly" do
|
191
|
+
m = Gmail::Message.new test_message
|
192
|
+
raw = Mail.new(Base64.urlsafe_decode64(m.raw))
|
193
|
+
assert raw.from
|
194
|
+
assert raw.to
|
195
|
+
assert raw.cc
|
196
|
+
assert_equal m.bcc, raw.header['Bcc'].value
|
197
|
+
assert_equal m.subject, raw.subject
|
198
|
+
assert_equal m.in_reply_to, "<#{raw.in_reply_to}>"
|
199
|
+
assert_equal m.references.tr("<", "").tr(">", "").split(" "), raw.references
|
200
|
+
assert raw.text_part.body.raw_source
|
201
|
+
assert raw.html_part.body.raw_source
|
202
|
+
end
|
203
|
+
|
204
|
+
should "Draft can be created from Message" do
|
205
|
+
m = Gmail::Message.new test_message
|
206
|
+
# raw generation change between two calls because date won't be the same...
|
207
|
+
m.raw = m.raw
|
208
|
+
###
|
209
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.drafts.create, parameters: {userId: "me"}, body_object:{message: {raw: m.raw, threadId: test_message[:threadId], labelIds: test_message[:labelIds]}} , headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_draft))
|
210
|
+
d = m.create_draft
|
211
|
+
assert_equal Gmail::Draft, d.class
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
should "Message should be sendable and return a Message" do
|
216
|
+
|
217
|
+
m = Gmail::Message.new test_message
|
218
|
+
m.raw = m.raw
|
219
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.to_h['gmail.users.messages.send'], parameters: {userId: "me"}, body_object:{raw: m.raw, labelIds: test_message[:labelIds], threadId: test_message[:threadId]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
220
|
+
|
221
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.get, parameters: {userId: "me", id: test_message[:id]}, headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_message))
|
222
|
+
|
223
|
+
|
224
|
+
new_m = m.deliver
|
225
|
+
assert_equal Gmail::Message, new_m.class
|
226
|
+
assert_not_equal new_m.object_id, m.object_id
|
227
|
+
|
228
|
+
new_m = m.deliver!
|
229
|
+
assert_equal Gmail::Message, new_m.class
|
230
|
+
assert_equal new_m.object_id, m.object_id
|
231
|
+
end
|
232
|
+
|
233
|
+
|
234
|
+
should "Reply to sender should be easy" do
|
235
|
+
m = Gmail::Message.new test_to_reply_message
|
236
|
+
reply_message = Gmail::Message.new test_reply_message
|
237
|
+
@mock.expects(:execute).once.returns(test_response(test_replied_message))
|
238
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.get, parameters: {userId: "me", id: test_replied_message[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_replied_message))
|
239
|
+
|
240
|
+
new_m = m.reply_sender_with reply_message
|
241
|
+
# to be completed to be fully tested
|
242
|
+
|
243
|
+
end
|
244
|
+
|
245
|
+
should "Reply to all should be easy" do
|
246
|
+
m = Gmail::Message.new test_to_reply_message
|
247
|
+
reply_message = Gmail::Message.new test_reply_message
|
248
|
+
@mock.expects(:execute).once.returns(test_response(test_replied_message))
|
249
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.get, parameters: {userId: "me", id: test_replied_message[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_replied_message))
|
250
|
+
|
251
|
+
new_m = m.reply_all_with reply_message
|
252
|
+
# to be completed to be fully tested
|
253
|
+
end
|
254
|
+
|
255
|
+
should "forward should be easy" do
|
256
|
+
m = Gmail::Message.new test_to_reply_message
|
257
|
+
forward_message = Gmail::Message.new test_reply_message(to: "test@test.com", bbc: "coucou", cc: "test@couocu.com, second@second.com", subject: "cool subject", body: "test")
|
258
|
+
@mock.expects(:execute).once.returns(test_response(test_replied_message))
|
259
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.messages.get, parameters: {userId: "me", id: test_replied_message[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_replied_message))
|
260
|
+
|
261
|
+
new_m = m.forward_with forward_message
|
262
|
+
# to be completed to be fully tested
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
end
|
@@ -0,0 +1,184 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require File.expand_path('../../test_helper', __FILE__)
|
3
|
+
|
4
|
+
module Gmail
|
5
|
+
class ThreadTest < Test::Unit::TestCase
|
6
|
+
|
7
|
+
should "Threads should be listable" do
|
8
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.list, parameters: {userId: "me"}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_thread_list))
|
9
|
+
list = Gmail::Thread.all
|
10
|
+
assert_equal Array, list.class
|
11
|
+
assert_equal Gmail::Thread, list[0].class
|
12
|
+
end
|
13
|
+
|
14
|
+
should "Thread should be retrievable by id" do
|
15
|
+
|
16
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.get, parameters: {userId: "me", id: test_thread[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_thread))
|
17
|
+
t = Gmail::Thread.get(test_thread[:id])
|
18
|
+
assert_equal Gmail::Thread, t.class
|
19
|
+
assert_equal test_thread[:id], t.id
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
context "Access list of Messages from thread" do
|
24
|
+
should "Access list of Messages" do
|
25
|
+
thread = Gmail::Thread.new test_thread
|
26
|
+
# @mock.expects(:execute).with(api_method: Gmail.service.users.messages.list, parameters: {userId: "me", threadId: [test_thread[:id]]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message_list))
|
27
|
+
list = thread.messages
|
28
|
+
assert_equal Array, list.class
|
29
|
+
assert_equal Gmail::Message, list[0].class
|
30
|
+
end
|
31
|
+
|
32
|
+
should "Access list of Messages after selecting from list" do
|
33
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.list, parameters: {userId: "me"}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_thread_list))
|
34
|
+
thread_list = Gmail::Thread.all
|
35
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.get, parameters: {userId: "me", id: test_thread[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message_list))
|
36
|
+
thread = thread_list.first
|
37
|
+
list = thread.messages
|
38
|
+
assert_equal Array, list.class
|
39
|
+
assert_equal Gmail::Message, list[0].class
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
should 'Access list of unread Messages' do
|
44
|
+
thread = Gmail::Thread.new test_thread
|
45
|
+
#@mock.expects(:execute).with(api_method: Gmail.service.users.messages.list, parameters: {userId: "me", threadId: [test_thread[:id]], labelIds: ["UNREAD"]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message_list))
|
46
|
+
list = thread.unread_messages
|
47
|
+
assert_equal Array, list.class
|
48
|
+
assert_equal Gmail::Message, list[0].class
|
49
|
+
end
|
50
|
+
|
51
|
+
should 'Access list of sent Messages' do
|
52
|
+
thread = Gmail::Thread.new test_thread
|
53
|
+
# @mock.expects(:execute).with(api_method: Gmail.service.users.messages.list, parameters: {userId: "me", threadId: [test_thread[:id]], labelIds: ["SENT"]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_message_list))
|
54
|
+
list = thread.unread_messages
|
55
|
+
assert_equal Array, list.class
|
56
|
+
assert_equal Gmail::Message, list[0].class
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
should "Thread should be deletable" do
|
62
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.delete, parameters: {userId: "me", id: test_thread[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(""))
|
63
|
+
t = Gmail::Thread.new(test_thread)
|
64
|
+
r = t.delete
|
65
|
+
assert r
|
66
|
+
end
|
67
|
+
|
68
|
+
should "Thread should be thrashable" do
|
69
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.trash, parameters: {userId: "me", id: test_thread[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_thread))
|
70
|
+
t = Gmail::Thread.new(test_thread)
|
71
|
+
r = t.trash
|
72
|
+
assert_equal Gmail::Thread, r.class
|
73
|
+
end
|
74
|
+
|
75
|
+
should "Thread should be unthrashable" do
|
76
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.untrash, parameters: {userId: "me", id: test_thread[:id]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_thread))
|
77
|
+
t = Gmail::Thread.new(test_thread)
|
78
|
+
r = t.untrash
|
79
|
+
assert_equal Gmail::Thread, r.class
|
80
|
+
end
|
81
|
+
|
82
|
+
context "Modifying Labels" do
|
83
|
+
should "Thread should be starrable" do
|
84
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.modify, parameters: {userId: "me", id: test_thread[:id]}, body_object: {addLabelIds: ["STARRED"], removeLabelIds: []} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_thread))
|
85
|
+
t = Gmail::Thread.new(test_thread)
|
86
|
+
r = t.star
|
87
|
+
assert_equal Gmail::Thread, r.class
|
88
|
+
assert_not_equal t.object_id, r.object_id
|
89
|
+
|
90
|
+
r = t.star!
|
91
|
+
|
92
|
+
assert_equal t.object_id, r.object_id
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
should "Thread should be unstarrable" do
|
97
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.modify, parameters: {userId: "me", id: test_thread[:id]}, body_object: {addLabelIds: [], removeLabelIds: ["STARRED"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_thread))
|
98
|
+
t = Gmail::Thread.new(test_thread)
|
99
|
+
r = t.unstar
|
100
|
+
assert_equal Gmail::Thread, r.class
|
101
|
+
|
102
|
+
assert_not_equal t.object_id, r.object_id
|
103
|
+
|
104
|
+
r = t.unstar!
|
105
|
+
|
106
|
+
assert_equal t.object_id, r.object_id
|
107
|
+
end
|
108
|
+
|
109
|
+
should "Thread should be archivable" do
|
110
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.modify, parameters: {userId: "me", id: test_thread[:id]}, body_object: {addLabelIds: [], removeLabelIds: ["INBOX"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_thread))
|
111
|
+
t = Gmail::Thread.new(test_thread)
|
112
|
+
r = t.archive
|
113
|
+
assert_equal Gmail::Thread, r.class
|
114
|
+
assert_not_equal t.object_id, r.object_id
|
115
|
+
|
116
|
+
r = t.archive!
|
117
|
+
|
118
|
+
assert_equal t.object_id, r.object_id
|
119
|
+
end
|
120
|
+
|
121
|
+
should "Thread should be unarchivable" do
|
122
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.modify, parameters: {userId: "me", id: test_thread[:id]}, body_object: {addLabelIds: ["INBOX"], removeLabelIds: []} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_thread))
|
123
|
+
t = Gmail::Thread.new(test_thread)
|
124
|
+
r = t.unarchive
|
125
|
+
assert_equal Gmail::Thread, r.class
|
126
|
+
assert_not_equal t.object_id, r.object_id
|
127
|
+
|
128
|
+
r = t.unarchive!
|
129
|
+
|
130
|
+
assert_equal t.object_id, r.object_id
|
131
|
+
end
|
132
|
+
|
133
|
+
should "Thread should be markable as read" do
|
134
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.modify, parameters: {userId: "me", id: test_thread[:id]}, body_object: {addLabelIds: [], removeLabelIds: ["UNREAD"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_thread))
|
135
|
+
t = Gmail::Thread.new(test_thread)
|
136
|
+
r = t.mark_as_read
|
137
|
+
assert_equal Gmail::Thread, r.class
|
138
|
+
assert_not_equal t.object_id, r.object_id
|
139
|
+
|
140
|
+
r = t.mark_as_read!
|
141
|
+
|
142
|
+
assert_equal t.object_id, r.object_id
|
143
|
+
end
|
144
|
+
|
145
|
+
should "Thread should be markable as unread" do
|
146
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.modify, parameters: {userId: "me", id: test_thread[:id]}, body_object: {addLabelIds: ["UNREAD"], removeLabelIds: []} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_thread))
|
147
|
+
t = Gmail::Thread.new(test_thread)
|
148
|
+
r = t.mark_as_unread
|
149
|
+
assert_equal Gmail::Thread, r.class
|
150
|
+
assert_not_equal t.object_id, r.object_id
|
151
|
+
|
152
|
+
r = t.mark_as_unread!
|
153
|
+
|
154
|
+
assert_equal t.object_id, r.object_id
|
155
|
+
end
|
156
|
+
|
157
|
+
|
158
|
+
should "Thread label should be modifiable as wish" do
|
159
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.modify, parameters: {userId: "me", id: test_thread[:id]}, body_object: {addLabelIds: ["UNREAD", "SOME COOL LABEL"], removeLabelIds: ["INBOX", "SOME NOT COOL LABEL"]} , headers: {'Content-Type' => 'application/json'}).twice.returns(test_response(test_thread))
|
160
|
+
t = Gmail::Thread.new(test_thread)
|
161
|
+
r = t.modify ["UNREAD", "SOME COOL LABEL"], ["INBOX", "SOME NOT COOL LABEL"]
|
162
|
+
assert_equal Gmail::Thread, r.class
|
163
|
+
assert_not_equal t.object_id, r.object_id
|
164
|
+
|
165
|
+
r = t.modify! ["UNREAD", "SOME COOL LABEL"], ["INBOX", "SOME NOT COOL LABEL"]
|
166
|
+
|
167
|
+
assert_equal t.object_id, r.object_id
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
|
173
|
+
should "Thread should be searcheable" do
|
174
|
+
@mock.expects(:execute).with(api_method: Gmail.service.users.threads.list, parameters: {userId: "me", q: "from:(me) to:(you) subject:(subject) in:inbox before:2014/12/1 after:2014/11/1 test -{real}", labelIds:["UNREAD"]}, headers: {'Content-Type' => 'application/json'}).once.returns(test_response(test_thread_list))
|
175
|
+
list = Gmail::Thread.search(from:"me", to: "you", subject: "subject", in: "inbox", before: "2014/12/1", after: "2014/11/1", has_words: "test", has_not_words: "real", labelIds: ["UNREAD"])
|
176
|
+
assert_equal Array, list.class
|
177
|
+
assert_equal Gmail::Thread, list[0].class
|
178
|
+
end
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
end
|
184
|
+
end
|