mandrill_dm 1.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Appraisals +11 -0
- data/CHANGELOG.md +51 -0
- data/Gemfile +2 -0
- data/LICENSE +21 -0
- data/MIGRATE +27 -0
- data/README.md +104 -0
- data/Rakefile +35 -0
- data/lib/mandrill_dm/delivery_method.rb +38 -0
- data/lib/mandrill_dm/message.rb +277 -0
- data/lib/mandrill_dm/railtie.rb +11 -0
- data/lib/mandrill_dm.rb +37 -0
- data/mandrill_dm.gemspec +27 -0
- data/spec/mandrill_dm/delivery_method_integration_spec.rb +108 -0
- data/spec/mandrill_dm/delivery_method_spec.rb +171 -0
- data/spec/mandrill_dm/message_spec.rb +752 -0
- data/spec/spec_helper.rb +33 -0
- metadata +201 -0
@@ -0,0 +1,752 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MandrillDm::Message do
|
4
|
+
def new_mail(options = {}, &blk)
|
5
|
+
Mail.new(options, &blk)
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#attachments' do
|
9
|
+
it 'takes an attachment' do
|
10
|
+
mail = new_mail(to: 'name@domain.tld', content_type: 'multipart/alternative')
|
11
|
+
mail.attachments['text.txt'] = {
|
12
|
+
mime_type: 'text/plain',
|
13
|
+
content: 'This is a test'
|
14
|
+
}
|
15
|
+
|
16
|
+
message = described_class.new(mail)
|
17
|
+
expect(message.attachments).to eq(
|
18
|
+
[{ name: 'text.txt', type: 'text/plain', content: "VGhpcyBpcyBhIHRlc3Q=\n" }]
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'ignores inline attachments' do
|
23
|
+
mail = new_mail(to: 'name@domain.tld', content_type: 'multipart/alternative')
|
24
|
+
mail.attachments.inline['text.txt'] = {
|
25
|
+
mime_type: 'text/plain',
|
26
|
+
content: 'This is a test'
|
27
|
+
}
|
28
|
+
|
29
|
+
message = described_class.new(mail)
|
30
|
+
expect(message.attachments).to eq([])
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#auto_html' do
|
35
|
+
it 'takes a auto_html with true' do
|
36
|
+
mail = new_mail(auto_html: true)
|
37
|
+
message = described_class.new(mail)
|
38
|
+
expect(message.auto_html).to be true
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'takes a auto_html with false' do
|
42
|
+
mail = new_mail(auto_html: false)
|
43
|
+
message = described_class.new(mail)
|
44
|
+
expect(message.auto_html).to be false
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'does not take an auto_html value' do
|
48
|
+
mail = new_mail
|
49
|
+
message = described_class.new(mail)
|
50
|
+
expect(message.auto_html).to be_nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#auto_text' do
|
55
|
+
it 'takes a auto_text with true' do
|
56
|
+
mail = new_mail(auto_text: true)
|
57
|
+
message = described_class.new(mail)
|
58
|
+
expect(message.auto_text).to be true
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'takes a auto_text with false' do
|
62
|
+
mail = new_mail(auto_text: false)
|
63
|
+
message = described_class.new(mail)
|
64
|
+
expect(message.auto_text).to be false
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'does not take an auto_text value' do
|
68
|
+
mail = new_mail
|
69
|
+
message = described_class.new(mail)
|
70
|
+
expect(message.auto_text).to be_nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#bcc_address' do
|
75
|
+
it 'takes a bcc_address' do
|
76
|
+
mail = new_mail(bcc_address: 'bart@simpsons.com')
|
77
|
+
message = described_class.new(mail)
|
78
|
+
expect(message.bcc_address).to eq('bart@simpsons.com')
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'does not take bcc_address value' do
|
82
|
+
mail = new_mail
|
83
|
+
message = described_class.new(mail)
|
84
|
+
expect(message.bcc_address).to be_nil
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#from_email' do
|
89
|
+
it 'takes a single email' do
|
90
|
+
mail = new_mail(from: 'from_name@domain.tld')
|
91
|
+
message = described_class.new(mail)
|
92
|
+
expect(message.from_email).to eq('from_name@domain.tld')
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'takes a single email with a display name' do
|
96
|
+
mail = new_mail(from: 'John Doe <from_name@domain.tld>')
|
97
|
+
message = described_class.new(mail)
|
98
|
+
expect(message.from_email).to eq('from_name@domain.tld')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe '#from_name' do
|
103
|
+
it 'takes a single email' do
|
104
|
+
mail = new_mail(from: 'from_name@domain.tld')
|
105
|
+
message = described_class.new(mail)
|
106
|
+
expect(message.from_name).to eq(nil)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'takes a single email with a display name' do
|
110
|
+
mail = new_mail(from: 'John Doe <from_name@domain.tld>')
|
111
|
+
message = described_class.new(mail)
|
112
|
+
expect(message.from_name).to eq('John Doe')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#global_merge_vars' do
|
117
|
+
it 'takes an array of global_merge_vars' do
|
118
|
+
global_merge_vars = [{ 'name' => 'TESTVAR', 'content' => 'testcontent' }]
|
119
|
+
mail = new_mail(global_merge_vars: global_merge_vars)
|
120
|
+
message = described_class.new(mail)
|
121
|
+
expect(message.global_merge_vars).to eq(global_merge_vars)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'takes an array of multiple global_merge_vars' do
|
125
|
+
global_merge_vars = [
|
126
|
+
{ 'name' => 'TESTVAR', 'content' => 'testcontent' },
|
127
|
+
{ 'name' => 'TESTVAR2', 'content' => 'testcontent2' }
|
128
|
+
]
|
129
|
+
mail = new_mail(global_merge_vars: global_merge_vars)
|
130
|
+
message = described_class.new(mail)
|
131
|
+
expect(message.global_merge_vars).to eq(global_merge_vars)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'does not use gsub to convert string into JSON' do
|
135
|
+
global_merge_vars = [
|
136
|
+
{ 'name' => 'TESTVAR', 'content' => 'do you know how :async works?' },
|
137
|
+
{ 'name' => 'TESTVAR2', 'content' => 'more than 10 recipients => always "true"!' }
|
138
|
+
]
|
139
|
+
mail = new_mail(global_merge_vars: global_merge_vars)
|
140
|
+
message = described_class.new(mail)
|
141
|
+
expect(message.global_merge_vars).to eq(global_merge_vars)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'does not take global_merge_vars value' do
|
145
|
+
mail = new_mail
|
146
|
+
message = described_class.new(mail)
|
147
|
+
expect(message.global_merge_vars).to be_nil
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
pending '#google_analytics_domains'
|
152
|
+
pending '#google_analytics_campaign'
|
153
|
+
|
154
|
+
describe '#headers' do
|
155
|
+
let(:headers) do
|
156
|
+
{
|
157
|
+
'Reply-To' => 'name1@domain.tld',
|
158
|
+
'X-MC-BccAddress' => 'name1@domain.tld',
|
159
|
+
'X-MY-CUSTOM-HEADER' => 'whatever'
|
160
|
+
}
|
161
|
+
end
|
162
|
+
|
163
|
+
let(:mail) { new_mail(headers: headers) }
|
164
|
+
subject { described_class.new(mail) }
|
165
|
+
|
166
|
+
it 'returns all headers' do
|
167
|
+
expect(subject.headers).to eq(headers)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe '#html' do
|
172
|
+
it 'takes a non-multipart message' do
|
173
|
+
mail = new_mail(
|
174
|
+
to: 'name@domain.tld',
|
175
|
+
body: '<html><body>Hello world!</body></html>',
|
176
|
+
content_type: 'text/html'
|
177
|
+
)
|
178
|
+
|
179
|
+
message = described_class.new(mail)
|
180
|
+
expect(message.html).to eq('<html><body>Hello world!</body></html>')
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'takes a multipart message' do
|
184
|
+
html_part = Mail::Part.new do
|
185
|
+
content_type 'text/html'
|
186
|
+
body '<html><body>Hello world!</body></html>'
|
187
|
+
end
|
188
|
+
|
189
|
+
text_part = Mail::Part.new do
|
190
|
+
content_type 'text/plain'
|
191
|
+
body 'Hello world!'
|
192
|
+
end
|
193
|
+
|
194
|
+
mail = new_mail(to: 'name@domain.tld', content_type: 'multipart/alternative') do |p|
|
195
|
+
p.html_part = html_part
|
196
|
+
p.text_part = text_part
|
197
|
+
end
|
198
|
+
message = described_class.new(mail)
|
199
|
+
expect(message.html).to eq('<html><body>Hello world!</body></html>')
|
200
|
+
end
|
201
|
+
|
202
|
+
it 'does not takes a text message' do
|
203
|
+
mail = new_mail(
|
204
|
+
to: 'name@domain.tld',
|
205
|
+
body: 'Hello world!',
|
206
|
+
content_type: 'text/plain'
|
207
|
+
)
|
208
|
+
message = described_class.new(mail)
|
209
|
+
expect(message.html).to eq(nil)
|
210
|
+
end
|
211
|
+
|
212
|
+
it 'does not take with the wrong content type' do
|
213
|
+
mail = new_mail(
|
214
|
+
to: 'name@domain.tld',
|
215
|
+
body: '<html><body>Hello world!</body></html>',
|
216
|
+
content_type: 'anytext/html5'
|
217
|
+
)
|
218
|
+
|
219
|
+
message = described_class.new(mail)
|
220
|
+
expect(message.html).to eq(nil)
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'takes with more thing in the content type' do
|
224
|
+
mail = new_mail(
|
225
|
+
to: 'name@domain.tld',
|
226
|
+
body: '<html><body>Hello world!</body></html>',
|
227
|
+
content_type: 'text/html; charset="us-ascii"'
|
228
|
+
)
|
229
|
+
|
230
|
+
message = described_class.new(mail)
|
231
|
+
expect(message.html).to eq('<html><body>Hello world!</body></html>')
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
describe '#images' do
|
236
|
+
it 'takes an inline attachment' do
|
237
|
+
mail = new_mail(to: 'name@domain.tld', content_type: 'multipart/alternative')
|
238
|
+
mail.attachments.inline['text.jpg'] = {
|
239
|
+
mime_type: 'image/jpg',
|
240
|
+
content: 'This is a test'
|
241
|
+
}
|
242
|
+
|
243
|
+
message = described_class.new(mail)
|
244
|
+
expect(message.images).to eq(
|
245
|
+
[{ name: mail.attachments[0].cid,
|
246
|
+
type: 'image/jpg',
|
247
|
+
content: "VGhpcyBpcyBhIHRlc3Q=\n" }]
|
248
|
+
)
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'ignores normal attachments' do
|
252
|
+
mail = new_mail(to: 'name@domain.tld', content_type: 'multipart/alternative')
|
253
|
+
mail.attachments['text.txt'] = {
|
254
|
+
mime_type: 'text/plain',
|
255
|
+
content: 'This is a test'
|
256
|
+
}
|
257
|
+
|
258
|
+
message = described_class.new(mail)
|
259
|
+
expect(message.images).to eq([])
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
describe '#important' do
|
264
|
+
it 'takes an important email' do
|
265
|
+
mail = new_mail(important: true)
|
266
|
+
message = described_class.new(mail)
|
267
|
+
expect(message.important).to be true
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'takes a non-important email' do
|
271
|
+
mail = new_mail(important: false)
|
272
|
+
message = described_class.new(mail)
|
273
|
+
expect(message.important).to be false
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'takes a default important value' do
|
277
|
+
mail = new_mail
|
278
|
+
message = described_class.new(mail)
|
279
|
+
expect(message.important).to be false
|
280
|
+
end
|
281
|
+
end
|
282
|
+
|
283
|
+
describe '#inline_css' do
|
284
|
+
it 'takes a inline_css with true' do
|
285
|
+
mail = new_mail(inline_css: true)
|
286
|
+
message = described_class.new(mail)
|
287
|
+
expect(message.inline_css).to be true
|
288
|
+
end
|
289
|
+
|
290
|
+
it 'takes a inline_css with false' do
|
291
|
+
mail = new_mail(inline_css: false)
|
292
|
+
message = described_class.new(mail)
|
293
|
+
expect(message.inline_css).to be false
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'does not take an inline_css value' do
|
297
|
+
mail = new_mail
|
298
|
+
message = described_class.new(mail)
|
299
|
+
expect(message.inline_css).to be_nil
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
describe '#merge' do
|
304
|
+
it 'takes a merge with true' do
|
305
|
+
mail = new_mail(merge: true)
|
306
|
+
message = described_class.new(mail)
|
307
|
+
expect(message.merge).to be true
|
308
|
+
end
|
309
|
+
|
310
|
+
it 'takes a merge with false' do
|
311
|
+
mail = new_mail(merge: false)
|
312
|
+
message = described_class.new(mail)
|
313
|
+
expect(message.merge).to be false
|
314
|
+
end
|
315
|
+
|
316
|
+
it 'does not take a merge value' do
|
317
|
+
mail = new_mail
|
318
|
+
message = described_class.new(mail)
|
319
|
+
expect(message.merge).to be_nil
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
describe '#merge_language' do
|
324
|
+
it 'takes a merge_language' do
|
325
|
+
mail = new_mail(merge_language: 'handlebars')
|
326
|
+
message = described_class.new(mail)
|
327
|
+
expect(message.merge_language).to eq('handlebars')
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'does not take merge_language value' do
|
331
|
+
mail = new_mail
|
332
|
+
message = described_class.new(mail)
|
333
|
+
expect(message.merge_language).to be_nil
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe '#merge_vars' do
|
338
|
+
it 'takes an array of merge_vars definitions' do
|
339
|
+
vars = [
|
340
|
+
{ 'name' => 'MY_VAR_1', 'content' => 'foo' },
|
341
|
+
{ 'name' => 'MY_VAR_2', 'content' => 'bar' }
|
342
|
+
]
|
343
|
+
merge_vars = [{ 'rcpt' => 'a@a.de', 'vars' => vars }]
|
344
|
+
mail = new_mail(merge_vars: merge_vars)
|
345
|
+
message = described_class.new(mail)
|
346
|
+
expect(message.merge_vars).to eq(merge_vars)
|
347
|
+
end
|
348
|
+
|
349
|
+
it 'takes an array of multiple merge_vars' do
|
350
|
+
vars = [
|
351
|
+
{ 'name' => 'MY_VAR_1', 'content' => 'foo' },
|
352
|
+
{ 'name' => 'MY_VAR_2', 'content' => 'bar' }
|
353
|
+
]
|
354
|
+
merge_vars = [
|
355
|
+
{ 'rcpt' => 'name1@domain.tld', 'vars' => vars },
|
356
|
+
{ 'rcpt' => 'name2@domain.tld', 'vars' => vars }
|
357
|
+
]
|
358
|
+
mail = new_mail(merge_vars: merge_vars)
|
359
|
+
message = described_class.new(mail)
|
360
|
+
expect(message.merge_vars).to eq(merge_vars)
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'does not use gsub to convert string into JSON' do
|
364
|
+
vars = [
|
365
|
+
{ 'name' => 'MY_VAR_1', 'content' => 'do you know how :async works?' },
|
366
|
+
{ 'name' => 'MY_VAR_2', 'content' => 'more than 10 recipients => always true!' }
|
367
|
+
]
|
368
|
+
merge_vars = [{ 'rcpt' => 'a@a.de', 'vars' => vars }]
|
369
|
+
mail = new_mail(merge_vars: merge_vars)
|
370
|
+
message = described_class.new(mail)
|
371
|
+
expect(message.merge_vars).to eq(merge_vars)
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'does not take merge_vars value' do
|
375
|
+
mail = new_mail
|
376
|
+
message = described_class.new(mail)
|
377
|
+
expect(message.merge_vars).to be_nil
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
describe '#metadata' do
|
382
|
+
it 'takes a metadata with a hash' do
|
383
|
+
mail = new_mail(metadata: { mail_internal_id: 'nice-uuid-field' })
|
384
|
+
message = described_class.new(mail)
|
385
|
+
expect(message.metadata).to eq('mail_internal_id' => 'nice-uuid-field')
|
386
|
+
end
|
387
|
+
|
388
|
+
it 'does not take metadata value' do
|
389
|
+
mail = new_mail
|
390
|
+
message = described_class.new(mail)
|
391
|
+
expect(message.metadata).to be_nil
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
describe '#preserve_recipients' do
|
396
|
+
it 'takes a preserve_recipients with true' do
|
397
|
+
mail = new_mail(preserve_recipients: true)
|
398
|
+
message = described_class.new(mail)
|
399
|
+
expect(message.preserve_recipients).to be true
|
400
|
+
end
|
401
|
+
|
402
|
+
it 'takes a preserve_recipients with false' do
|
403
|
+
mail = new_mail(preserve_recipients: false)
|
404
|
+
message = described_class.new(mail)
|
405
|
+
expect(message.preserve_recipients).to be false
|
406
|
+
end
|
407
|
+
|
408
|
+
it 'does not take preserve_recipients value' do
|
409
|
+
mail = new_mail
|
410
|
+
message = described_class.new(mail)
|
411
|
+
expect(message.preserve_recipients).to be_nil
|
412
|
+
end
|
413
|
+
end
|
414
|
+
|
415
|
+
pending '#recipient_metadata'
|
416
|
+
|
417
|
+
describe '#return_path_domain' do
|
418
|
+
it 'takes a return_path_domain' do
|
419
|
+
mail = new_mail(return_path_domain: 'return_path_domain.com')
|
420
|
+
message = described_class.new(mail)
|
421
|
+
expect(message.return_path_domain).to eq('return_path_domain.com')
|
422
|
+
end
|
423
|
+
|
424
|
+
it 'does not take return_path_domain value' do
|
425
|
+
mail = new_mail
|
426
|
+
message = described_class.new(mail)
|
427
|
+
expect(message.return_path_domain).to be_nil
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
describe '#send_at' do
|
432
|
+
it 'takes a Date and raises an ArgumentError' do
|
433
|
+
mail = new_mail(send_at: Date.new(2016))
|
434
|
+
message = described_class.new(mail)
|
435
|
+
expect { message.send_at }.to raise_error(ArgumentError)
|
436
|
+
end
|
437
|
+
|
438
|
+
it 'takes a string and returns it as is' do
|
439
|
+
mail = new_mail(send_at: '2010-01-01 12:00:00')
|
440
|
+
message = described_class.new(mail)
|
441
|
+
expect(message.send_at).to eq('2010-01-01 12:00:00')
|
442
|
+
end
|
443
|
+
|
444
|
+
it 'takes a DateTime and returns a string in UTC' do
|
445
|
+
mail = new_mail(send_at: DateTime.parse('2016-01-01 00:00:00 -0800'))
|
446
|
+
message = described_class.new(mail)
|
447
|
+
expect(message.send_at).to eq('2016-01-01 08:00:00')
|
448
|
+
end
|
449
|
+
|
450
|
+
it 'takes a Time and returns a string in UTC' do
|
451
|
+
mail = new_mail(send_at: Time.parse('2016-01-01 00:00:00 -0800'))
|
452
|
+
message = described_class.new(mail)
|
453
|
+
expect(message.send_at).to eq('2016-01-01 08:00:00')
|
454
|
+
end
|
455
|
+
end
|
456
|
+
|
457
|
+
describe '#signing_domain' do
|
458
|
+
it 'takes a signing_domain' do
|
459
|
+
mail = new_mail(signing_domain: 'signing_domain.com')
|
460
|
+
message = described_class.new(mail)
|
461
|
+
expect(message.signing_domain).to eq('signing_domain.com')
|
462
|
+
end
|
463
|
+
|
464
|
+
it 'does not take signing_domain value' do
|
465
|
+
mail = new_mail
|
466
|
+
message = described_class.new(mail)
|
467
|
+
expect(message.signing_domain).to be_nil
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
describe '#subaccount' do
|
472
|
+
it 'takes a subaccount' do
|
473
|
+
mail = new_mail(subaccount: 'abc123')
|
474
|
+
message = described_class.new(mail)
|
475
|
+
expect(message.subaccount).to eq('abc123')
|
476
|
+
end
|
477
|
+
|
478
|
+
it 'does not take subaccount value' do
|
479
|
+
mail = new_mail
|
480
|
+
message = described_class.new(mail)
|
481
|
+
expect(message.subaccount).to be_nil
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
describe '#subject' do
|
486
|
+
it 'takes a subject' do
|
487
|
+
mail = new_mail(subject: 'Test Subject')
|
488
|
+
message = described_class.new(mail)
|
489
|
+
expect(message.subject).to eq('Test Subject')
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
describe '#tags' do
|
494
|
+
it 'takes a tag' do
|
495
|
+
mail = new_mail(tags: 'test_tag')
|
496
|
+
message = described_class.new(mail)
|
497
|
+
expect(message.tags).to eq(['test_tag'])
|
498
|
+
end
|
499
|
+
|
500
|
+
it 'takes an array of tags' do
|
501
|
+
mail = new_mail(tags: %w[test_tag1 test_tag2])
|
502
|
+
message = described_class.new(mail)
|
503
|
+
expect(message.tags).to eq(%w[test_tag1 test_tag2])
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
describe '#text' do
|
508
|
+
it 'does not take a non-multipart message' do
|
509
|
+
mail = new_mail(to: 'name@domain.tld', body: 'Hello world!')
|
510
|
+
message = described_class.new(mail)
|
511
|
+
expect(message.text).to eq(nil)
|
512
|
+
end
|
513
|
+
|
514
|
+
it 'does not take with the wrong content type' do
|
515
|
+
mail = new_mail(
|
516
|
+
to: 'name@domain.tld',
|
517
|
+
body: 'Hello world!',
|
518
|
+
content_type: 'anytext/plain'
|
519
|
+
)
|
520
|
+
|
521
|
+
message = described_class.new(mail)
|
522
|
+
expect(message.text).to eq(nil)
|
523
|
+
end
|
524
|
+
|
525
|
+
it 'takes with more thing in the content type' do
|
526
|
+
mail = new_mail(
|
527
|
+
to: 'name@domain.tld',
|
528
|
+
body: 'Hello world!',
|
529
|
+
content_type: 'text/plain; charset="us-ascii"'
|
530
|
+
)
|
531
|
+
|
532
|
+
message = described_class.new(mail)
|
533
|
+
expect(message.text).to eq('Hello world!')
|
534
|
+
end
|
535
|
+
|
536
|
+
it 'takes a text message' do
|
537
|
+
mail = new_mail(
|
538
|
+
to: 'name@domain.tld',
|
539
|
+
body: 'Hello world!',
|
540
|
+
content_type: 'text/plain'
|
541
|
+
)
|
542
|
+
message = described_class.new(mail)
|
543
|
+
expect(message.text).to eq('Hello world!')
|
544
|
+
end
|
545
|
+
|
546
|
+
it 'takes a multipart message' do
|
547
|
+
html_part = Mail::Part.new do
|
548
|
+
content_type 'text/html'
|
549
|
+
body '<html><body>Hello world!</body></html>'
|
550
|
+
end
|
551
|
+
|
552
|
+
text_part = Mail::Part.new do
|
553
|
+
content_type 'text/plain'
|
554
|
+
body 'Hello world!'
|
555
|
+
end
|
556
|
+
|
557
|
+
mail = new_mail(to: 'name@domain.tld', content_type: 'multipart/alternative') do |p|
|
558
|
+
p.html_part = html_part
|
559
|
+
p.text_part = text_part
|
560
|
+
end
|
561
|
+
message = described_class.new(mail)
|
562
|
+
expect(message.text).to eq('Hello world!')
|
563
|
+
end
|
564
|
+
end
|
565
|
+
|
566
|
+
describe '#to' do
|
567
|
+
it 'takes a single email' do
|
568
|
+
mail = new_mail(to: 'name@domain.tld')
|
569
|
+
message = described_class.new(mail)
|
570
|
+
expect(message.to).to eq([{ email: 'name@domain.tld', name: nil, type: 'to' }])
|
571
|
+
end
|
572
|
+
|
573
|
+
it 'takes a single email with a display name' do
|
574
|
+
mail = new_mail(to: 'John Doe <name@domain.tld>')
|
575
|
+
message = described_class.new(mail)
|
576
|
+
expect(message.to).to eq(
|
577
|
+
[{ email: 'name@domain.tld', name: 'John Doe', type: 'to' }]
|
578
|
+
)
|
579
|
+
end
|
580
|
+
|
581
|
+
it 'takes an array of emails' do
|
582
|
+
mail = new_mail(to: ['name1@domain.tld', 'name2@domain.tld'])
|
583
|
+
message = described_class.new(mail)
|
584
|
+
expect(message.to).to eq(
|
585
|
+
[
|
586
|
+
{ email: 'name1@domain.tld', name: nil, type: 'to' },
|
587
|
+
{ email: 'name2@domain.tld', name: nil, type: 'to' }
|
588
|
+
]
|
589
|
+
)
|
590
|
+
end
|
591
|
+
|
592
|
+
it 'takes an array of emails with a display names' do
|
593
|
+
mail = new_mail(
|
594
|
+
to: ['John Doe <name1@domain.tld>', 'Jane Smith <name2@domain.tld>']
|
595
|
+
)
|
596
|
+
|
597
|
+
message = described_class.new(mail)
|
598
|
+
expect(message.to).to eq(
|
599
|
+
[
|
600
|
+
{ email: 'name1@domain.tld', name: 'John Doe', type: 'to' },
|
601
|
+
{ email: 'name2@domain.tld', name: 'Jane Smith', type: 'to' }
|
602
|
+
]
|
603
|
+
)
|
604
|
+
end
|
605
|
+
|
606
|
+
it 'combines to, cc, and bcc fields' do
|
607
|
+
mail = new_mail(
|
608
|
+
to: 'John Doe <name1@domain.tld>',
|
609
|
+
cc: 'Jane Smith <name2@domain.tld>',
|
610
|
+
bcc: 'Jenny Craig <name3@domain.tld>'
|
611
|
+
)
|
612
|
+
|
613
|
+
message = described_class.new(mail)
|
614
|
+
expect(message.to).to eq(
|
615
|
+
[
|
616
|
+
{ email: 'name1@domain.tld', name: 'John Doe', type: 'to' },
|
617
|
+
{ email: 'name2@domain.tld', name: 'Jane Smith', type: 'cc' },
|
618
|
+
{ email: 'name3@domain.tld', name: 'Jenny Craig', type: 'bcc' }
|
619
|
+
]
|
620
|
+
)
|
621
|
+
end
|
622
|
+
end
|
623
|
+
|
624
|
+
describe '#track_clicks' do
|
625
|
+
it 'takes a track_clicks with true' do
|
626
|
+
mail = new_mail(track_clicks: true)
|
627
|
+
message = described_class.new(mail)
|
628
|
+
expect(message.track_clicks).to be true
|
629
|
+
end
|
630
|
+
|
631
|
+
it 'takes a track_clicks with false' do
|
632
|
+
mail = new_mail(track_clicks: false)
|
633
|
+
message = described_class.new(mail)
|
634
|
+
expect(message.track_clicks).to be false
|
635
|
+
end
|
636
|
+
|
637
|
+
it 'does not take a track_clicks value' do
|
638
|
+
mail = new_mail
|
639
|
+
message = described_class.new(mail)
|
640
|
+
expect(message.track_clicks).to be_nil
|
641
|
+
end
|
642
|
+
end
|
643
|
+
|
644
|
+
describe '#track_opens' do
|
645
|
+
it 'takes a track_opens with true' do
|
646
|
+
mail = new_mail(track_opens: true)
|
647
|
+
message = described_class.new(mail)
|
648
|
+
expect(message.track_opens).to be true
|
649
|
+
end
|
650
|
+
|
651
|
+
it 'takes a track_opens with false' do
|
652
|
+
mail = new_mail(track_opens: false)
|
653
|
+
message = described_class.new(mail)
|
654
|
+
expect(message.track_opens).to be false
|
655
|
+
end
|
656
|
+
|
657
|
+
it 'does not take a track_opens value' do
|
658
|
+
mail = new_mail
|
659
|
+
message = described_class.new(mail)
|
660
|
+
expect(message.track_opens).to be_nil
|
661
|
+
end
|
662
|
+
end
|
663
|
+
|
664
|
+
describe '#tracking_domain' do
|
665
|
+
it 'takes a tracking_domain' do
|
666
|
+
mail = new_mail(tracking_domain: 'tracking_domain.com')
|
667
|
+
message = described_class.new(mail)
|
668
|
+
expect(message.tracking_domain).to eq('tracking_domain.com')
|
669
|
+
end
|
670
|
+
|
671
|
+
it 'does not take tracking_domain value' do
|
672
|
+
mail = new_mail
|
673
|
+
message = described_class.new(mail)
|
674
|
+
expect(message.tracking_domain).to be_nil
|
675
|
+
end
|
676
|
+
end
|
677
|
+
|
678
|
+
describe '#url_strip_qs' do
|
679
|
+
it 'takes a url_strip_qs with true' do
|
680
|
+
mail = new_mail(url_strip_qs: true)
|
681
|
+
message = described_class.new(mail)
|
682
|
+
expect(message.url_strip_qs).to be true
|
683
|
+
end
|
684
|
+
|
685
|
+
it 'takes a url_strip_qs with false' do
|
686
|
+
mail = new_mail(url_strip_qs: false)
|
687
|
+
message = described_class.new(mail)
|
688
|
+
expect(message.url_strip_qs).to be false
|
689
|
+
end
|
690
|
+
|
691
|
+
it 'does not take an url_strip_qs value' do
|
692
|
+
mail = new_mail
|
693
|
+
message = described_class.new(mail)
|
694
|
+
expect(message.url_strip_qs).to be_nil
|
695
|
+
end
|
696
|
+
end
|
697
|
+
|
698
|
+
describe '#view_content_link' do
|
699
|
+
it 'takes a view_content_link with true' do
|
700
|
+
mail = new_mail(view_content_link: true)
|
701
|
+
message = described_class.new(mail)
|
702
|
+
expect(message.view_content_link).to be true
|
703
|
+
end
|
704
|
+
|
705
|
+
it 'takes a view_content_link with false' do
|
706
|
+
mail = new_mail(view_content_link: false)
|
707
|
+
message = described_class.new(mail)
|
708
|
+
expect(message.view_content_link).to be false
|
709
|
+
end
|
710
|
+
|
711
|
+
it 'does not take view_content_link value' do
|
712
|
+
mail = new_mail
|
713
|
+
message = described_class.new(mail)
|
714
|
+
expect(message.view_content_link).to be_nil
|
715
|
+
end
|
716
|
+
end
|
717
|
+
|
718
|
+
describe '#to_json' do
|
719
|
+
it 'returns a proper JSON response for the Mandrill API' do
|
720
|
+
mail = new_mail(body: 'test',
|
721
|
+
from: 'name@domain.tld',
|
722
|
+
headers: { 'Reply-To' => 'name1@domain.tld' },
|
723
|
+
tags: 'test_tag')
|
724
|
+
message = described_class.new(mail)
|
725
|
+
expect(message.to_json).to(
|
726
|
+
include(:from_email, :from_name, :html, :subject, :to, :headers, :tags)
|
727
|
+
)
|
728
|
+
end
|
729
|
+
|
730
|
+
it 'returns a proper JSON response for the Mandrill API with attachments' do
|
731
|
+
mail = new_mail(body: 'test', from: 'name@domain.tld')
|
732
|
+
mail.attachments['text.txt'] = {
|
733
|
+
mime_type: 'text/plain',
|
734
|
+
content: 'This is a test'
|
735
|
+
}
|
736
|
+
|
737
|
+
message = described_class.new(mail)
|
738
|
+
expect(message.to_json).to(
|
739
|
+
include(:from_email, :from_name, :html, :subject, :to, :attachments)
|
740
|
+
)
|
741
|
+
end
|
742
|
+
|
743
|
+
it 'returns a proper JSON response for the Mandrill API with metadata' do
|
744
|
+
mail = new_mail(body: 'test', from: 'name@domain.tld', metadata: { foo: 'bar' })
|
745
|
+
|
746
|
+
message = described_class.new(mail)
|
747
|
+
expect(message.to_json).to(
|
748
|
+
include(:from_email, :from_name, :html, :subject, :to, :metadata)
|
749
|
+
)
|
750
|
+
end
|
751
|
+
end
|
752
|
+
end
|