multi_mail 0.0.2 → 0.1.0
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.
- data/.gitignore +2 -1
- data/.travis.yml +10 -0
- data/README.md +283 -59
- data/Rakefile +38 -19
- data/lib/multi_mail/cloudmailin/receiver.rb +3 -13
- data/lib/multi_mail/mailgun/message.rb +67 -0
- data/lib/multi_mail/mailgun/receiver.rb +20 -13
- data/lib/multi_mail/mailgun/sender.rb +79 -2
- data/lib/multi_mail/mandrill/message.rb +74 -0
- data/lib/multi_mail/mandrill/receiver.rb +36 -16
- data/lib/multi_mail/mandrill/sender.rb +77 -2
- data/lib/multi_mail/message/base.rb +40 -0
- data/lib/multi_mail/postmark/receiver.rb +1 -1
- data/lib/multi_mail/postmark/sender.rb +35 -5
- data/lib/multi_mail/receiver/base.rb +31 -2
- data/lib/multi_mail/receiver.rb +1 -4
- data/lib/multi_mail/sender/base.rb +23 -1
- data/lib/multi_mail/sendgrid/message.rb +74 -0
- data/lib/multi_mail/sendgrid/receiver.rb +72 -23
- data/lib/multi_mail/sendgrid/sender.rb +63 -2
- data/lib/multi_mail/service.rb +48 -56
- data/lib/multi_mail/simple/receiver.rb +4 -4
- data/lib/multi_mail/version.rb +1 -1
- data/lib/multi_mail.rb +16 -1
- data/multi_mail.gemspec +4 -1
- data/spec/fixtures/empty.gif +0 -0
- data/spec/fixtures/mailgun/raw/invalid.txt +13 -0
- data/spec/fixtures/mailgun/raw/missing.txt +13 -0
- data/spec/fixtures/mailgun/raw/spam.txt +13 -0
- data/spec/fixtures/mailgun/raw/valid.txt +13 -0
- data/spec/fixtures/mandrill/invalid.txt +15 -0
- data/spec/fixtures/mandrill/missing.txt +14 -0
- data/spec/fixtures/mandrill/multiple.txt +15 -0
- data/spec/fixtures/mandrill/valid.txt +10 -5
- data/spec/fixtures/postmark/valid.txt +13 -13
- data/spec/fixtures/sendgrid/encoding.txt +90 -0
- data/spec/fixtures/sendgrid/spam.txt +94 -0
- data/spec/fixtures/sendgrid/valid.txt +136 -0
- data/spec/mailgun/message_spec.rb +251 -0
- data/spec/mailgun/receiver_spec.rb +35 -20
- data/spec/mailgun/sender_spec.rb +175 -0
- data/spec/mandrill/message_spec.rb +305 -0
- data/spec/mandrill/receiver_spec.rb +90 -46
- data/spec/mandrill/sender_spec.rb +138 -0
- data/spec/message/base_spec.rb +81 -0
- data/spec/postmark/receiver_spec.rb +4 -4
- data/spec/postmark/sender_spec.rb +118 -0
- data/spec/receiver/base_spec.rb +16 -9
- data/spec/sender/base_spec.rb +24 -10
- data/spec/sendgrid/message_spec.rb +265 -0
- data/spec/sendgrid/receiver_spec.rb +77 -0
- data/spec/sendgrid/sender_spec.rb +140 -0
- data/spec/service_spec.rb +18 -1
- data/spec/simple/receiver_spec.rb +1 -1
- data/spec/spec_helper.rb +46 -4
- metadata +226 -143
- data/lib/multi_mail/sender.rb +0 -46
- data/lib/multi_mail/simple/sender.rb +0 -14
- data/spec/sender_spec.rb +0 -13
- data/spec/simple/sender_spec.rb +0 -0
@@ -0,0 +1,305 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'multi_mail/mandrill/message'
|
3
|
+
|
4
|
+
describe MultiMail::Message::Mandrill do
|
5
|
+
let :message do
|
6
|
+
headers = {
|
7
|
+
'X-Autoreply' => true,
|
8
|
+
'X-Precedence' => 'auto_reply',
|
9
|
+
'X-Numeric' => 42,
|
10
|
+
'Delivered-To' => 'Autoresponder',
|
11
|
+
}
|
12
|
+
|
13
|
+
MultiMail::Message::Mandrill.new do
|
14
|
+
date Time.at(946702800)
|
15
|
+
headers headers
|
16
|
+
from %("John Doe" <foo@example.com>)
|
17
|
+
to [%("Jane Doe" <bar@example.com>), '<baz@example.com>']
|
18
|
+
cc 'cc@example.com'
|
19
|
+
bcc 'bcc@example.com'
|
20
|
+
reply_to 'noreply@example.com'
|
21
|
+
subject 'test'
|
22
|
+
|
23
|
+
text_part do
|
24
|
+
body 'hello'
|
25
|
+
end
|
26
|
+
|
27
|
+
html_part do
|
28
|
+
content_type 'text/html; charset=UTF-8'
|
29
|
+
body '<p>hello</p>'
|
30
|
+
end
|
31
|
+
|
32
|
+
add_file empty_gif_path
|
33
|
+
add_file :filename => 'foo.txt', :content => 'hello world'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
let :message_without_names do
|
38
|
+
MultiMail::Message::Mandrill.new do
|
39
|
+
from 'foo@example.com'
|
40
|
+
to ['bar@example.com', 'baz@example.com']
|
41
|
+
subject 'test'
|
42
|
+
body 'hello'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
let :message_with_known_extension do
|
47
|
+
MultiMail::Message::Mandrill.new do
|
48
|
+
from 'foo@example.com'
|
49
|
+
to 'bar@example.com'
|
50
|
+
subject 'test'
|
51
|
+
body 'hello'
|
52
|
+
add_file :filename => 'xxx.mov', :content => ''
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
let :message_with_unknown_extension do
|
57
|
+
MultiMail::Message::Mandrill.new do
|
58
|
+
from 'foo@example.com'
|
59
|
+
to 'bar@example.com'
|
60
|
+
subject 'test'
|
61
|
+
body 'hello'
|
62
|
+
add_file :filename => 'xxx.xxx', :content => ''
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
let :message_without_extension do
|
67
|
+
MultiMail::Message::Mandrill.new do
|
68
|
+
from 'foo@example.com'
|
69
|
+
to 'bar@example.com'
|
70
|
+
subject 'test'
|
71
|
+
body 'hello'
|
72
|
+
add_file :filename => 'xxx', :content => ''
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
let :message_with_empty_file do
|
77
|
+
MultiMail::Message::Mandrill.new do
|
78
|
+
from 'foo@example.com'
|
79
|
+
to 'bar@example.com'
|
80
|
+
subject 'test'
|
81
|
+
body 'hello'
|
82
|
+
add_file :filename => '', :content => ''
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
let :message_with_empty_headers do
|
87
|
+
headers = {
|
88
|
+
'X-Autoreply' => nil,
|
89
|
+
}
|
90
|
+
|
91
|
+
MultiMail::Message::Mandrill.new do
|
92
|
+
headers headers
|
93
|
+
from 'foo@example.com'
|
94
|
+
to 'bar@example.com'
|
95
|
+
reply_to nil
|
96
|
+
subject 'test'
|
97
|
+
body 'hello'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
let :message_without_html_body do
|
102
|
+
MultiMail::Message::Mandrill.new do
|
103
|
+
from 'foo@example.com'
|
104
|
+
to 'bar@example.com'
|
105
|
+
subject 'test'
|
106
|
+
body 'hello'
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
let :message_without_text_body do
|
111
|
+
MultiMail::Message::Mandrill.new do
|
112
|
+
from 'foo@example.com'
|
113
|
+
to 'bar@example.com'
|
114
|
+
subject 'test'
|
115
|
+
body '<p>hello</p>'
|
116
|
+
content_type 'text/html; charset=UTF-8'
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
let :empty_message do
|
121
|
+
MultiMail::Message::Mandrill.new
|
122
|
+
end
|
123
|
+
|
124
|
+
describe '#mandrill_to' do
|
125
|
+
it 'should return the recipients with names' do
|
126
|
+
message.mandrill_to.should == [
|
127
|
+
{
|
128
|
+
'email' => 'bar@example.com',
|
129
|
+
'name' => 'Jane Doe',
|
130
|
+
},
|
131
|
+
{
|
132
|
+
'email' => 'baz@example.com',
|
133
|
+
'name' => nil,
|
134
|
+
},
|
135
|
+
]
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should return the recipients without names' do
|
139
|
+
message_without_names.mandrill_to.should == [
|
140
|
+
{
|
141
|
+
'email' => 'bar@example.com',
|
142
|
+
'name' => nil,
|
143
|
+
},
|
144
|
+
{
|
145
|
+
'email' => 'baz@example.com',
|
146
|
+
'name' => nil,
|
147
|
+
},
|
148
|
+
]
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should return an empty array' do
|
152
|
+
empty_message.mandrill_to.should == []
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#mandrill_headers' do
|
157
|
+
it 'should return only the Reply-To and X-* headers' do
|
158
|
+
headers = message.mandrill_headers
|
159
|
+
headers.should == {
|
160
|
+
'Reply-To' => 'noreply@example.com',
|
161
|
+
'X-Autoreply' => 'true',
|
162
|
+
'X-Precedence' => 'auto_reply',
|
163
|
+
'X-Numeric' => '42',
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should return empty X-* headers' do
|
168
|
+
headers = message_with_empty_headers.mandrill_headers
|
169
|
+
headers.should == {'X-Autoreply' => ''}
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'should return an empty hash' do
|
173
|
+
empty_message.mandrill_headers.should == {}
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '#mandrill_attachments' do
|
178
|
+
it 'should return the attachments' do
|
179
|
+
message.mandrill_attachments.should == [
|
180
|
+
{
|
181
|
+
'type' => 'image/gif; filename=empty.gif',
|
182
|
+
'name' => 'empty.gif',
|
183
|
+
'content' => "R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n",
|
184
|
+
},
|
185
|
+
{
|
186
|
+
'type' => 'text/plain; filename=foo.txt',
|
187
|
+
'name' => 'foo.txt',
|
188
|
+
'content' => Base64.encode64('hello world'),
|
189
|
+
},
|
190
|
+
]
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should return an attachment with an known extension' do
|
194
|
+
message_with_known_extension.mandrill_attachments.should == [
|
195
|
+
{
|
196
|
+
'type' => 'video/quicktime; filename=xxx.mov',
|
197
|
+
'name' => 'xxx.mov',
|
198
|
+
'content' => '',
|
199
|
+
},
|
200
|
+
]
|
201
|
+
end
|
202
|
+
|
203
|
+
it 'should return an attachment with an unknown extension' do
|
204
|
+
message_with_unknown_extension.mandrill_attachments.should == [
|
205
|
+
{
|
206
|
+
'type' => 'text/plain',
|
207
|
+
'name' => 'xxx.xxx',
|
208
|
+
'content' => '',
|
209
|
+
},
|
210
|
+
]
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'should return an attachment without an extension' do
|
214
|
+
message_without_extension.mandrill_attachments.should == [
|
215
|
+
{
|
216
|
+
'type' => 'text/plain',
|
217
|
+
'name' => 'xxx',
|
218
|
+
'content' => '',
|
219
|
+
},
|
220
|
+
]
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should return an empty array if the attachment is blank' do
|
224
|
+
message_with_empty_file.mandrill_attachments.should == []
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should return an empty array' do
|
228
|
+
empty_message.mandrill_attachments.should == []
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
describe '#to_mandrill_hash' do
|
233
|
+
it 'should return the message as Mandrill parameters' do
|
234
|
+
message.to_mandrill_hash.should == {
|
235
|
+
:html => '<p>hello</p>',
|
236
|
+
:text => 'hello',
|
237
|
+
:subject => 'test',
|
238
|
+
:from_email => 'foo@example.com',
|
239
|
+
:from_name => 'John Doe',
|
240
|
+
:to => [
|
241
|
+
{
|
242
|
+
'email' => 'bar@example.com',
|
243
|
+
'name' => 'Jane Doe',
|
244
|
+
},
|
245
|
+
{
|
246
|
+
'email' => 'baz@example.com',
|
247
|
+
'name' => nil,
|
248
|
+
},
|
249
|
+
],
|
250
|
+
:headers => {
|
251
|
+
'Reply-To' => 'noreply@example.com',
|
252
|
+
'X-Autoreply' => 'true',
|
253
|
+
'X-Precedence' => 'auto_reply',
|
254
|
+
'X-Numeric' => '42',
|
255
|
+
},
|
256
|
+
:attachments => [
|
257
|
+
{
|
258
|
+
'type' => 'text/plain; filename=foo.txt',
|
259
|
+
'name' => 'foo.txt',
|
260
|
+
'content' => Base64.encode64('hello world'),
|
261
|
+
},
|
262
|
+
],
|
263
|
+
:images => [
|
264
|
+
{
|
265
|
+
'type' => 'image/gif; filename=empty.gif',
|
266
|
+
'name' => 'empty.gif',
|
267
|
+
'content' => "R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==\n",
|
268
|
+
},
|
269
|
+
],
|
270
|
+
}
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'should convert the message without a text body' do
|
274
|
+
message_without_text_body.to_mandrill_hash.should == {
|
275
|
+
:html => '<p>hello</p>',
|
276
|
+
:subject => 'test',
|
277
|
+
:from_email => 'foo@example.com',
|
278
|
+
:to => [
|
279
|
+
{
|
280
|
+
'email' => 'bar@example.com',
|
281
|
+
'name' => nil,
|
282
|
+
},
|
283
|
+
],
|
284
|
+
}
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'should convert the message without an HTML body' do
|
288
|
+
message_without_html_body.to_mandrill_hash.should == {
|
289
|
+
:text => 'hello',
|
290
|
+
:subject => 'test',
|
291
|
+
:from_email => 'foo@example.com',
|
292
|
+
:to => [
|
293
|
+
{
|
294
|
+
'email' => 'bar@example.com',
|
295
|
+
'name' => nil,
|
296
|
+
},
|
297
|
+
],
|
298
|
+
}
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'should convert an empty message' do
|
302
|
+
empty_message.to_mandrill_hash.should == {}
|
303
|
+
end
|
304
|
+
end
|
305
|
+
end
|
@@ -3,61 +3,105 @@ require 'multi_mail/mandrill/receiver'
|
|
3
3
|
|
4
4
|
describe MultiMail::Receiver::Mandrill do
|
5
5
|
context 'after initialization' do
|
6
|
-
let :service do
|
7
|
-
MultiMail::Receiver.new(:provider => :mandrill)
|
8
|
-
end
|
9
|
-
|
10
6
|
def params(fixture)
|
11
7
|
MultiMail::Receiver::Mandrill.parse(response('mandrill', fixture))
|
12
8
|
end
|
13
9
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
message.parts[1].content_type.should == 'text/html; charset=UTF-8'
|
32
|
-
# @note Mandrill adds a newline at the end of each part.
|
33
|
-
message.parts[0].body.decoded.should == "bold text\n\n\n\nsome more bold text\n\n\n\nsome italic text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block\n"
|
34
|
-
message.parts[1].body.decoded.should == %(<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body></html><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><b></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><i>some italic text</i></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>)
|
35
|
-
|
36
|
-
# Attachments
|
37
|
-
attachment0 = message.attachments.find{|attachment| attachment.filename == 'foo.txt'}
|
38
|
-
attachment1 = message.attachments.find{|attachment| attachment.filename == 'bar.txt'}
|
39
|
-
attachment0.read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\n"
|
40
|
-
attachment1.read.should == "Nam accumsan euismod eros et rhoncus.\n\n"
|
41
|
-
|
42
|
-
# Extra Mandrill parameters
|
43
|
-
message['ts'].value.should == '1368657709'
|
44
|
-
message['email'].value.should == 'foo+bar@govkit.org'
|
45
|
-
message['dkim-signed'].value.should == 'false'
|
46
|
-
message['dkim-valid'].value.should == 'false'
|
47
|
-
message['spam_report-score'].value.should == '0'
|
48
|
-
message['spf-result'].value.should == 'pass'
|
10
|
+
context 'without optional arguments' do
|
11
|
+
let :service do
|
12
|
+
MultiMail::Receiver.new(:provider => :mandrill)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#valid?' do
|
16
|
+
it 'should return true if the response is valid' do
|
17
|
+
service.valid?(params('valid')).should == true
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return true if the response is invalid' do
|
21
|
+
service.valid?(params('invalid')).should == true
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return true if parameters are missing' do
|
25
|
+
service.valid?(params('missing')).should == true
|
26
|
+
end
|
49
27
|
end
|
50
28
|
end
|
51
29
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
30
|
+
context 'with optional arguments' do
|
31
|
+
let :service do
|
32
|
+
MultiMail::Receiver.new({
|
33
|
+
:provider => :mandrill,
|
34
|
+
:mandrill_webhook_key => 'rth_rywL9CWIIZBuwPQIWw',
|
35
|
+
:mandrill_webhook_url => 'http://rackbin.herokuapp.com/',
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#valid?' do
|
40
|
+
it 'should return true if the response is valid' do
|
41
|
+
service.valid?(params('valid')).should == true
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should return false if the response is invalid' do
|
45
|
+
service.valid?(params('invalid')).should == false
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should raise an error if parameters are missing' do
|
49
|
+
expect{ service.valid?(params('missing')) }.to raise_error(IndexError)
|
50
|
+
end
|
56
51
|
end
|
57
52
|
|
58
|
-
|
59
|
-
|
60
|
-
|
53
|
+
describe '#transform' do
|
54
|
+
it 'should return a mail message' do
|
55
|
+
messages = service.transform(params('valid'))
|
56
|
+
messages.size.should == 1
|
57
|
+
message = messages[0]
|
58
|
+
|
59
|
+
# Headers
|
60
|
+
message.date.should == DateTime.parse('Mon, 29 May 2013 16:51:45 -04:00')
|
61
|
+
message.from.should == ['james@opennorth.ca']
|
62
|
+
message.to.should == ['foo+bar@govkit.org']
|
63
|
+
message.subject.should == 'Test'
|
64
|
+
|
65
|
+
# Body
|
66
|
+
message.multipart?.should == true
|
67
|
+
message.parts.size.should == 4
|
68
|
+
message.parts[0].content_type.should == 'text/plain'
|
69
|
+
message.parts[1].content_type.should == 'text/html; charset=UTF-8'
|
70
|
+
# @note Mandrill adds a newline at the end of each part.
|
71
|
+
message.parts[0].body.decoded.should == "bold text\n\n\n\nsome more bold text\n\n\n\nsome italic text\n\n> multiline\n> quoted\n> text\n\n\n--\nSignature block\n"
|
72
|
+
message.parts[1].body.decoded.should == %(<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><b>bold text</b><div><br></div><div></div></body></html><html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><head></head><br><div></div><div><br></div><div><b>some more bold text</b></div><div><b><br></b></div><div><b></b></div></body></html><html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><b></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><i>some italic text</i></span></b></div><div><b><span class="Apple-style-span" style="font-weight: normal; "><br></span></b></div><div><blockquote type="cite">multiline</blockquote><blockquote type="cite">quoted</blockquote><blockquote type="cite">text</blockquote></div><div><br></div><div>--</div><div>Signature block</div></body></html>)
|
73
|
+
|
74
|
+
# Attachments
|
75
|
+
attachment0 = message.attachments.find{|attachment| attachment.filename == 'foo.txt'}
|
76
|
+
attachment1 = message.attachments.find{|attachment| attachment.filename == 'bar.txt'}
|
77
|
+
attachment0.read.should == "Lorem ipsum dolor sit amet, consectetur adipiscing elit.\n\n"
|
78
|
+
attachment1.read.should == "Nam accumsan euismod eros et rhoncus.\n\n"
|
79
|
+
|
80
|
+
# Extra Mandrill parameters
|
81
|
+
message['ts'].value.should == '1369860716'
|
82
|
+
message['email'].value.should == 'foo+bar@govkit.org'
|
83
|
+
message['dkim-signed'].value.should == 'false'
|
84
|
+
message['dkim-valid'].value.should == 'false'
|
85
|
+
message['spam_report-score'].value.should == '-0.7'
|
86
|
+
message['spf-result'].value.should == 'pass'
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should return multiple messages if there are multiple events' do
|
90
|
+
messages = service.transform(params('multiple'))
|
91
|
+
messages.size.should == 2
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#spam?' do
|
96
|
+
it 'should return true if the response is spam' do
|
97
|
+
message = service.transform(params('spam'))[0]
|
98
|
+
service.spam?(message).should == true
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should return false if the response is ham' do
|
102
|
+
message = service.transform(params('valid'))[0]
|
103
|
+
service.spam?(message).should == false
|
104
|
+
end
|
61
105
|
end
|
62
106
|
end
|
63
107
|
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
require 'multi_mail/mandrill/sender'
|
3
|
+
|
4
|
+
describe MultiMail::Sender::Mandrill do
|
5
|
+
let :message do
|
6
|
+
Mail.new do
|
7
|
+
from 'foo@example.com'
|
8
|
+
to 'bar@example.com'
|
9
|
+
subject 'test'
|
10
|
+
body 'hello'
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let :empty_message do
|
15
|
+
Mail.new
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#initialize' do
|
19
|
+
it 'should raise an error if :api_key is missing' do
|
20
|
+
expect{
|
21
|
+
message.delivery_method MultiMail::Sender::Mandrill
|
22
|
+
message.deliver # request not sent
|
23
|
+
}.to raise_error(ArgumentError, "Missing required arguments: api_key")
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should raise an error if :api_key is nil' do
|
27
|
+
expect{
|
28
|
+
message.delivery_method MultiMail::Sender::Mandrill, :api_key => nil
|
29
|
+
message.deliver # request not sent
|
30
|
+
}.to raise_error(ArgumentError, "Missing required arguments: api_key")
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should raise an error if :api_key is invalid' do
|
34
|
+
expect{
|
35
|
+
message.delivery_method MultiMail::Sender::Mandrill, :api_key => 'xxx'
|
36
|
+
message.deliver
|
37
|
+
}.to raise_error(MultiMail::InvalidAPIKey, 'Invalid API key')
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should have default settings' do
|
41
|
+
sender = MultiMail::Sender::Mandrill.new(:api_key => '')
|
42
|
+
|
43
|
+
sender.api_key.should == ''
|
44
|
+
sender.async.should == false
|
45
|
+
sender.ip_pool.should == nil
|
46
|
+
sender.send_at.should == nil
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should assign custom settings' do
|
50
|
+
sender = MultiMail::Sender::Mandrill.new({
|
51
|
+
:api_key => 'xxx',
|
52
|
+
:async => true,
|
53
|
+
:ip_pool => 'Main Pool',
|
54
|
+
:send_at => 'example send_at',
|
55
|
+
})
|
56
|
+
|
57
|
+
sender.api_key.should == 'xxx'
|
58
|
+
sender.async.should == true
|
59
|
+
sender.ip_pool.should == 'Main Pool'
|
60
|
+
sender.send_at.should == 'example send_at'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#parameters' do
|
65
|
+
it 'should allow true, false and nil values' do
|
66
|
+
[true, false, nil].each do |value|
|
67
|
+
sender = MultiMail::Sender::Mandrill.new({
|
68
|
+
:api_key => 'xxx',
|
69
|
+
:track => {
|
70
|
+
:clicks => value,
|
71
|
+
}
|
72
|
+
})
|
73
|
+
|
74
|
+
sender.parameters.should == {:track_clicks => value}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should transform "yes" and "no" values' do
|
79
|
+
sender = MultiMail::Sender::Mandrill.new({
|
80
|
+
:api_key => 'xxx',
|
81
|
+
:track => {
|
82
|
+
:opens => 'no',
|
83
|
+
:clicks => 'yes',
|
84
|
+
}
|
85
|
+
})
|
86
|
+
|
87
|
+
sender.parameters.should == {:track_opens => false, :track_clicks => true}
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should ignore "htmlonly" values' do
|
91
|
+
sender = MultiMail::Sender::Mandrill.new({
|
92
|
+
:api_key => 'xxx',
|
93
|
+
:track => {
|
94
|
+
:clicks => 'htmlonly',
|
95
|
+
}
|
96
|
+
})
|
97
|
+
|
98
|
+
sender.parameters.should == {}
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#deliver' do
|
103
|
+
before :all do
|
104
|
+
Mail.defaults do
|
105
|
+
delivery_method MultiMail::Sender::Mandrill, :api_key => ENV['MANDRILL_API_KEY']
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should send a message' do
|
110
|
+
message.deliver.should == message
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe '#deliver!' do
|
115
|
+
before :all do
|
116
|
+
Mail.defaults do
|
117
|
+
delivery_method MultiMail::Sender::Mandrill, :api_key => ENV['MANDRILL_API_KEY'], :return_response => true
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should send a message' do
|
122
|
+
results = message.deliver!
|
123
|
+
results.size.should == 1
|
124
|
+
|
125
|
+
result = results.first
|
126
|
+
result.size.should == 4
|
127
|
+
|
128
|
+
result['reject_reason'].should == nil
|
129
|
+
result['status'].should == "sent"
|
130
|
+
result['email'].should == "bar@example.com"
|
131
|
+
result['_id'].should match(/\A[0-9a-f]{32}\z/)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should not send an empty message' do
|
135
|
+
empty_message.deliver!.should == [] # response not saved
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe MultiMail::Message::Base do
|
4
|
+
let :text_message do
|
5
|
+
MultiMail::Message::Base.new do
|
6
|
+
from 'foo@example.com'
|
7
|
+
to 'bar@example.com'
|
8
|
+
subject 'test'
|
9
|
+
body 'hello'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
let :html_message do
|
14
|
+
MultiMail::Message::Base.new do
|
15
|
+
from 'foo@example.com'
|
16
|
+
to 'bar@example.com'
|
17
|
+
subject 'test'
|
18
|
+
body '<p>hello</p>'
|
19
|
+
content_type 'text/html; charset=UTF-8'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
let :html_and_text_message do
|
24
|
+
MultiMail::Message::Base.new do
|
25
|
+
from 'foo@example.com'
|
26
|
+
to 'bar@example.com'
|
27
|
+
subject 'test'
|
28
|
+
|
29
|
+
text_part do
|
30
|
+
body 'hello'
|
31
|
+
end
|
32
|
+
|
33
|
+
html_part do
|
34
|
+
content_type 'text/html; charset=UTF-8'
|
35
|
+
body '<p>hello</p>'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe '#html?' do
|
41
|
+
it 'should return false if the message is text only' do
|
42
|
+
text_message.html?.should == false
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return true if the message is HTML only' do
|
46
|
+
html_message.html?.should == true
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should return false if the message has both HTML and text parts' do
|
50
|
+
html_and_text_message.html?.should == false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#body_html' do
|
55
|
+
it 'should not return the body if the message is text only' do
|
56
|
+
text_message.body_html.should be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should return the body if the message is HTML only' do
|
60
|
+
html_message.body_html.should == '<p>hello</p>'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should return the body if the message has both HTML and text parts' do
|
64
|
+
html_and_text_message.body_html.should == '<p>hello</p>'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#text_part' do
|
69
|
+
it 'should return the body if the message is text only' do
|
70
|
+
text_message.body_text.should == 'hello'
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should return not the body if the message is HTML only' do
|
74
|
+
html_message.body_text.should be_nil
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should return the body if the message has both HTML and text parts' do
|
78
|
+
html_and_text_message.body_text.should == 'hello'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|