mailgun-ruby 1.4.1 → 1.4.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/Gemfile +3 -1
- data/README.md +1 -1
- data/Rakefile +5 -3
- data/docs/AnalyticsTags.md +63 -0
- data/lib/mailgun/address.rb +5 -5
- data/lib/mailgun/chains.rb +2 -3
- data/lib/mailgun/client.rb +47 -51
- data/lib/mailgun/domains/domains.rb +7 -8
- data/lib/mailgun/events/events.rb +4 -3
- data/lib/mailgun/exceptions/exceptions.rb +12 -15
- data/lib/mailgun/helpers/api_version_checker.rb +6 -1
- data/lib/mailgun/lists/opt_in_handler.rb +4 -6
- data/lib/mailgun/logs/logs.rb +4 -2
- data/lib/mailgun/messages/batch_message.rb +8 -9
- data/lib/mailgun/messages/message_builder.rb +36 -24
- data/lib/mailgun/metrics/metrics.rb +6 -4
- data/lib/mailgun/response.rb +11 -9
- data/lib/mailgun/subaccounts/subaccounts.rb +13 -8
- data/lib/mailgun/suppressions.rb +36 -43
- data/lib/mailgun/tags/analytics_tags.rb +33 -2
- data/lib/mailgun/tags/tags.rb +25 -17
- data/lib/mailgun/templates/templates.rb +40 -29
- data/lib/mailgun/version.rb +3 -1
- data/lib/mailgun/webhooks/webhooks.rb +22 -19
- data/lib/mailgun-ruby.rb +2 -0
- data/lib/mailgun.rb +4 -4
- data/lib/railgun/attachment.rb +9 -14
- data/lib/railgun/errors.rb +2 -3
- data/lib/railgun/mailer.rb +35 -39
- data/lib/railgun/railtie.rb +2 -0
- data/lib/railgun.rb +2 -0
- data/mailgun.gemspec +12 -11
- data/spec/integration/analytics_tags_spec.rb +54 -0
- data/spec/integration/bounces_spec.rb +12 -11
- data/spec/integration/campaign_spec.rb +20 -18
- data/spec/integration/complaints_spec.rb +8 -6
- data/spec/integration/domains_spec.rb +6 -6
- data/spec/integration/email_validation_spec.rb +35 -34
- data/spec/integration/events_spec.rb +7 -5
- data/spec/integration/list_members_spec.rb +27 -26
- data/spec/integration/list_spec.rb +22 -21
- data/spec/integration/logs_spec.rb +48 -46
- data/spec/integration/mailer_spec.rb +7 -3
- data/spec/integration/mailgun_spec.rb +82 -90
- data/spec/integration/metrics_spec.rb +130 -130
- data/spec/integration/routes_spec.rb +41 -40
- data/spec/integration/stats_spec.rb +4 -2
- data/spec/integration/subaccounts_spec.rb +9 -10
- data/spec/integration/suppressions_spec.rb +21 -20
- data/spec/integration/templates_spec.rb +14 -12
- data/spec/integration/unsubscribes_spec.rb +8 -6
- data/spec/integration/webhook_spec.rb +13 -12
- data/spec/spec_helper.rb +8 -8
- data/spec/unit/connection/test_client.rb +61 -55
- data/spec/unit/events/events_spec.rb +25 -22
- data/spec/unit/exceptions/exceptions_spec.rb +8 -7
- data/spec/unit/lists/opt_in_handler_spec.rb +8 -6
- data/spec/unit/mailgun_spec.rb +64 -63
- data/spec/unit/messages/batch_message_spec.rb +15 -15
- data/spec/unit/messages/message_builder_spec.rb +98 -94
- data/spec/unit/railgun/content_type_spec.rb +24 -23
- data/spec/unit/railgun/mailer_spec.rb +58 -58
- data/vcr_cassettes/analytics_tags.yml +187 -0
- metadata +49 -33
- data/.rubocop.yml +0 -8
- data/.rubocop_todo.yml +0 -22
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'stringio'
|
|
3
5
|
|
|
4
6
|
describe 'MessageBuilder attribute readers' do
|
|
5
7
|
it 'should be readable' do
|
|
6
|
-
@mb_obj = Mailgun::MessageBuilder.new
|
|
8
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
|
7
9
|
|
|
8
10
|
expect(@mb_obj).to respond_to(:message)
|
|
9
11
|
expect(@mb_obj).to respond_to(:counters)
|
|
@@ -11,9 +13,8 @@ describe 'MessageBuilder attribute readers' do
|
|
|
11
13
|
end
|
|
12
14
|
|
|
13
15
|
describe 'The instantiation of MessageBuilder' do
|
|
14
|
-
|
|
15
16
|
before(:each) do
|
|
16
|
-
@mb_obj = Mailgun::MessageBuilder.new
|
|
17
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
it 'contains counters, which should be of type hash and contain several important counters' do
|
|
@@ -39,7 +40,7 @@ describe 'The method add_recipient' do
|
|
|
39
40
|
before(:each) do
|
|
40
41
|
@mb_obj = Mailgun::MessageBuilder.new
|
|
41
42
|
@address = 'jane@example.com'
|
|
42
|
-
@variables = {'first' => 'Jane', 'last' => 'Doe'}
|
|
43
|
+
@variables = { 'first' => 'Jane', 'last' => 'Doe' }
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
it 'adds a "to" recipient type to the message body and counter is incremented' do
|
|
@@ -55,7 +56,7 @@ describe 'The method add_recipient' do
|
|
|
55
56
|
recipient_type = :to
|
|
56
57
|
@mb_obj.add_recipient(recipient_type, @address, {})
|
|
57
58
|
|
|
58
|
-
expect(@mb_obj.message[recipient_type][0]).to eq(
|
|
59
|
+
expect(@mb_obj.message[recipient_type][0]).to eq(@address.to_s)
|
|
59
60
|
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1)
|
|
60
61
|
end
|
|
61
62
|
end
|
|
@@ -81,7 +82,7 @@ describe 'The method add_recipient' do
|
|
|
81
82
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
|
82
83
|
|
|
83
84
|
expect(@mb_obj.message[recipient_type]).to eq("'#{@variables['first']} #{@variables['last']}' <#{@address}>")
|
|
84
|
-
@mb_obj.counters[:recipients].each_value{|value| expect(value).to eq(0)}
|
|
85
|
+
@mb_obj.counters[:recipients].each_value { |value| expect(value).to eq(0) }
|
|
85
86
|
end
|
|
86
87
|
|
|
87
88
|
it 'ensures a random recipient type is added to the message body and counters are not incremented' do
|
|
@@ -89,31 +90,34 @@ describe 'The method add_recipient' do
|
|
|
89
90
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
|
90
91
|
|
|
91
92
|
expect(@mb_obj.message[recipient_type][0]).to eq("'#{@variables['first']} #{@variables['last']}' <#{@address}>")
|
|
92
|
-
@mb_obj.counters[:recipients].each_value{|value| expect(value).to eq(0)}
|
|
93
|
+
@mb_obj.counters[:recipients].each_value { |value| expect(value).to eq(0) }
|
|
93
94
|
end
|
|
94
95
|
it 'adds too many to recipients and raises an exception.' do
|
|
95
96
|
recipient_type = :to
|
|
96
97
|
|
|
97
|
-
expect
|
|
98
|
+
expect do
|
|
98
99
|
1001.times do
|
|
99
100
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
|
100
|
-
|
|
101
|
+
end
|
|
102
|
+
end.to raise_error(Mailgun::ParameterError)
|
|
101
103
|
end
|
|
102
104
|
it 'adds too many cc recipients and raises an exception.' do
|
|
103
105
|
recipient_type = :cc
|
|
104
106
|
|
|
105
|
-
expect
|
|
107
|
+
expect do
|
|
106
108
|
1001.times do
|
|
107
109
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
|
108
|
-
|
|
110
|
+
end
|
|
111
|
+
end.to raise_error(Mailgun::ParameterError)
|
|
109
112
|
end
|
|
110
113
|
it 'adds too many bcc recipients and raises an exception.' do
|
|
111
114
|
recipient_type = :bcc
|
|
112
115
|
|
|
113
|
-
expect
|
|
116
|
+
expect do
|
|
114
117
|
1001.times do
|
|
115
118
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
|
116
|
-
|
|
119
|
+
end
|
|
120
|
+
end.to raise_error(Mailgun::ParameterError)
|
|
117
121
|
end
|
|
118
122
|
end
|
|
119
123
|
|
|
@@ -195,7 +199,6 @@ describe 'The method amp_html' do
|
|
|
195
199
|
expect(@mb_obj.message['amp-html']).to eq(the_text)
|
|
196
200
|
end
|
|
197
201
|
end
|
|
198
|
-
|
|
199
202
|
|
|
200
203
|
describe 'The method set_from_address' do
|
|
201
204
|
it 'warns of set_from_address deprecation' do
|
|
@@ -221,7 +224,7 @@ describe 'The method from' do
|
|
|
221
224
|
the_from_address = 'test@mailgun.com'
|
|
222
225
|
the_first_name = 'Magilla'
|
|
223
226
|
the_last_name = 'Gorilla'
|
|
224
|
-
@mb_obj.from(the_from_address, {'first' => the_first_name, 'last' => the_last_name})
|
|
227
|
+
@mb_obj.from(the_from_address, { 'first' => the_first_name, 'last' => the_last_name })
|
|
225
228
|
|
|
226
229
|
expect(@mb_obj.message[:from]).to eq(["'#{the_first_name} #{the_last_name}' <#{the_from_address}>"])
|
|
227
230
|
end
|
|
@@ -229,7 +232,7 @@ describe 'The method from' do
|
|
|
229
232
|
it 'sets the from address with full name metadata' do
|
|
230
233
|
the_from_address = 'test@mailgun.com'
|
|
231
234
|
full_name = 'Magilla Gorilla'
|
|
232
|
-
@mb_obj.from(the_from_address, {'full_name' => full_name})
|
|
235
|
+
@mb_obj.from(the_from_address, { 'full_name' => full_name })
|
|
233
236
|
|
|
234
237
|
expect(@mb_obj.message[:from]).to eq(["'#{full_name}' <#{the_from_address}>"])
|
|
235
238
|
end
|
|
@@ -238,7 +241,7 @@ describe 'The method from' do
|
|
|
238
241
|
the_from_address = 'test@mailgun.com'
|
|
239
242
|
full_name = 'Magilla Gorilla'
|
|
240
243
|
first_name = 'Magilla'
|
|
241
|
-
expect{@mb_obj.from(the_from_address, {'full_name' => full_name, 'first' => first_name})}.to raise_error(Mailgun::ParameterError)
|
|
244
|
+
expect { @mb_obj.from(the_from_address, { 'full_name' => full_name, 'first' => first_name }) }.to raise_error(Mailgun::ParameterError)
|
|
242
245
|
end
|
|
243
246
|
end
|
|
244
247
|
|
|
@@ -247,20 +250,19 @@ describe 'The method add_attachment' do
|
|
|
247
250
|
@mb_obj = Mailgun::MessageBuilder.new
|
|
248
251
|
end
|
|
249
252
|
it 'adds a few file paths to the message object' do
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
file2 = File.dirname(__FILE__) + "/sample_data/rackspace_logo.jpg"
|
|
253
|
+
file1 = "#{File.dirname(__FILE__)}/sample_data/mailgun_icon.png"
|
|
254
|
+
file2 = "#{File.dirname(__FILE__)}/sample_data/rackspace_logo.jpg"
|
|
253
255
|
|
|
254
256
|
file_paths = [file1, file2]
|
|
255
257
|
|
|
256
|
-
file_paths.each {|item| @mb_obj.add_attachment(item)}
|
|
258
|
+
file_paths.each { |item| @mb_obj.add_attachment(item) }
|
|
257
259
|
|
|
258
260
|
expect(@mb_obj.message[:attachment].length).to eq(2)
|
|
259
261
|
end
|
|
260
262
|
|
|
261
263
|
it 'adds file-like objects to the message object' do
|
|
262
264
|
io = StringIO.new
|
|
263
|
-
io << File.binread(File.dirname(__FILE__)
|
|
265
|
+
io << File.binread("#{File.dirname(__FILE__)}/sample_data/mailgun_icon.png")
|
|
264
266
|
|
|
265
267
|
@mb_obj.add_attachment io, 'cool_attachment.png'
|
|
266
268
|
|
|
@@ -271,7 +273,7 @@ describe 'The method add_attachment' do
|
|
|
271
273
|
|
|
272
274
|
context 'when attachment has unknown type' do
|
|
273
275
|
it 'sets content type application/octet-stream for attachment' do
|
|
274
|
-
file = File.dirname(__FILE__)
|
|
276
|
+
file = "#{File.dirname(__FILE__)}/sample_data/unknown.type"
|
|
275
277
|
|
|
276
278
|
@mb_obj.add_attachment(file)
|
|
277
279
|
|
|
@@ -285,12 +287,12 @@ describe 'The method add_inline_image' do
|
|
|
285
287
|
@mb_obj = Mailgun::MessageBuilder.new
|
|
286
288
|
end
|
|
287
289
|
it 'adds a few file paths to the message object' do
|
|
288
|
-
file1 = File.dirname(__FILE__)
|
|
289
|
-
file2 = File.dirname(__FILE__)
|
|
290
|
+
file1 = "#{File.dirname(__FILE__)}/sample_data/mailgun_icon.png"
|
|
291
|
+
file2 = "#{File.dirname(__FILE__)}/sample_data/rackspace_logo.jpg"
|
|
290
292
|
|
|
291
293
|
file_paths = [file1, file2]
|
|
292
294
|
|
|
293
|
-
file_paths.each {|item| @mb_obj.add_inline_image(item)}
|
|
295
|
+
file_paths.each { |item| @mb_obj.add_inline_image(item) }
|
|
294
296
|
|
|
295
297
|
expect(@mb_obj.message[:inline].length).to eq(2)
|
|
296
298
|
end
|
|
@@ -313,7 +315,7 @@ describe 'The method list_unsubscribe' do
|
|
|
313
315
|
end
|
|
314
316
|
|
|
315
317
|
it 'sets the message list_unsubscribe if called with many list_unsubscribe parameters' do
|
|
316
|
-
unsubscribe_to = %w
|
|
318
|
+
unsubscribe_to = %w[http://example.com/stop-hassle mailto:stop-hassle@example.com]
|
|
317
319
|
@mb_obj.list_unsubscribe(*unsubscribe_to)
|
|
318
320
|
expect(@mb_obj.message['h:List-Unsubscribe']).to eq(
|
|
319
321
|
unsubscribe_to.map { |var| "<#{var}>" }.join(',')
|
|
@@ -336,30 +338,30 @@ describe 'The method test_mode' do
|
|
|
336
338
|
it 'turns on test mode with boolean true' do
|
|
337
339
|
@mb_obj.test_mode(true)
|
|
338
340
|
|
|
339
|
-
expect(@mb_obj.message[
|
|
341
|
+
expect(@mb_obj.message['o:testmode'][0]).to eq('yes')
|
|
340
342
|
end
|
|
341
343
|
it 'turns on test mode with string true' do
|
|
342
|
-
@mb_obj.test_mode(
|
|
344
|
+
@mb_obj.test_mode('true')
|
|
343
345
|
|
|
344
|
-
expect(@mb_obj.message[
|
|
346
|
+
expect(@mb_obj.message['o:testmode'][0]).to eq('yes')
|
|
345
347
|
end
|
|
346
348
|
it 'turns off test mode with boolean false' do
|
|
347
349
|
@mb_obj.test_mode(false)
|
|
348
350
|
|
|
349
|
-
expect(@mb_obj.message[
|
|
351
|
+
expect(@mb_obj.message['o:testmode'][0]).to eq('no')
|
|
350
352
|
end
|
|
351
353
|
it 'turns off test mode with string false' do
|
|
352
|
-
@mb_obj.test_mode(
|
|
354
|
+
@mb_obj.test_mode('false')
|
|
353
355
|
|
|
354
|
-
expect(@mb_obj.message[
|
|
356
|
+
expect(@mb_obj.message['o:testmode'][0]).to eq('no')
|
|
355
357
|
end
|
|
356
358
|
it 'does not allow multiple values' do
|
|
357
|
-
@mb_obj.test_mode(
|
|
358
|
-
@mb_obj.test_mode(
|
|
359
|
-
@mb_obj.test_mode(
|
|
359
|
+
@mb_obj.test_mode('false')
|
|
360
|
+
@mb_obj.test_mode('true')
|
|
361
|
+
@mb_obj.test_mode('false')
|
|
360
362
|
|
|
361
|
-
expect(@mb_obj.message[
|
|
362
|
-
expect(@mb_obj.message[
|
|
363
|
+
expect(@mb_obj.message['o:testmode'].length).to eq(1)
|
|
364
|
+
expect(@mb_obj.message['o:testmode'][0]).to eq('no')
|
|
363
365
|
end
|
|
364
366
|
end
|
|
365
367
|
|
|
@@ -378,30 +380,30 @@ describe 'The method dkim' do
|
|
|
378
380
|
it 'turns on dkim with boolean true' do
|
|
379
381
|
@mb_obj.dkim(true)
|
|
380
382
|
|
|
381
|
-
expect(@mb_obj.message[
|
|
383
|
+
expect(@mb_obj.message['o:dkim'][0]).to eq('yes')
|
|
382
384
|
end
|
|
383
385
|
it 'turns on dkim with string true' do
|
|
384
|
-
@mb_obj.dkim(
|
|
386
|
+
@mb_obj.dkim('true')
|
|
385
387
|
|
|
386
|
-
expect(@mb_obj.message[
|
|
388
|
+
expect(@mb_obj.message['o:dkim'][0]).to eq('yes')
|
|
387
389
|
end
|
|
388
390
|
it 'turns off dkim with boolean false' do
|
|
389
391
|
@mb_obj.dkim(false)
|
|
390
392
|
|
|
391
|
-
expect(@mb_obj.message[
|
|
393
|
+
expect(@mb_obj.message['o:dkim'][0]).to eq('no')
|
|
392
394
|
end
|
|
393
395
|
it 'turns off dkim with string false' do
|
|
394
|
-
@mb_obj.dkim(
|
|
396
|
+
@mb_obj.dkim('false')
|
|
395
397
|
|
|
396
|
-
expect(@mb_obj.message[
|
|
398
|
+
expect(@mb_obj.message['o:dkim'][0]).to eq('no')
|
|
397
399
|
end
|
|
398
400
|
it 'does not allow multiple values' do
|
|
399
|
-
@mb_obj.dkim(
|
|
400
|
-
@mb_obj.dkim(
|
|
401
|
-
@mb_obj.dkim(
|
|
401
|
+
@mb_obj.dkim('false')
|
|
402
|
+
@mb_obj.dkim('true')
|
|
403
|
+
@mb_obj.dkim('false')
|
|
402
404
|
|
|
403
|
-
expect(@mb_obj.message[
|
|
404
|
-
expect(@mb_obj.message[
|
|
405
|
+
expect(@mb_obj.message['o:dkim'].length).to eq(1)
|
|
406
|
+
expect(@mb_obj.message['o:dkim'][0]).to eq('no')
|
|
405
407
|
end
|
|
406
408
|
end
|
|
407
409
|
|
|
@@ -412,22 +414,23 @@ describe 'The method add_campaign_id' do
|
|
|
412
414
|
it 'adds a campaign ID to the message' do
|
|
413
415
|
@mb_obj.add_campaign_id('My-Campaign-Id-1')
|
|
414
416
|
|
|
415
|
-
expect(@mb_obj.message[
|
|
417
|
+
expect(@mb_obj.message['o:campaign'][0]).to eq('My-Campaign-Id-1')
|
|
416
418
|
end
|
|
417
419
|
it 'adds a few more campaign IDs to the message' do
|
|
418
420
|
@mb_obj.add_campaign_id('My-Campaign-Id-1')
|
|
419
421
|
@mb_obj.add_campaign_id('My-Campaign-Id-2')
|
|
420
422
|
@mb_obj.add_campaign_id('My-Campaign-Id-3')
|
|
421
423
|
|
|
422
|
-
expect(@mb_obj.message[
|
|
423
|
-
expect(@mb_obj.message[
|
|
424
|
-
expect(@mb_obj.message[
|
|
424
|
+
expect(@mb_obj.message['o:campaign'][0]).to eq('My-Campaign-Id-1')
|
|
425
|
+
expect(@mb_obj.message['o:campaign'][1]).to eq('My-Campaign-Id-2')
|
|
426
|
+
expect(@mb_obj.message['o:campaign'][2]).to eq('My-Campaign-Id-3')
|
|
425
427
|
end
|
|
426
428
|
it 'adds too many campaign IDs to the message' do
|
|
427
|
-
expect
|
|
429
|
+
expect do
|
|
428
430
|
10.times do
|
|
429
431
|
@mb_obj.add_campaign_id('Test-Campaign-ID')
|
|
430
|
-
|
|
432
|
+
end
|
|
433
|
+
end.to raise_error(Mailgun::ParameterError)
|
|
431
434
|
end
|
|
432
435
|
end
|
|
433
436
|
|
|
@@ -438,22 +441,23 @@ describe 'The method add_tag' do
|
|
|
438
441
|
it 'adds a tag to the message' do
|
|
439
442
|
@mb_obj.add_tag('My-Tag-1')
|
|
440
443
|
|
|
441
|
-
expect(@mb_obj.message[
|
|
444
|
+
expect(@mb_obj.message['o:tag'][0]).to eq('My-Tag-1')
|
|
442
445
|
end
|
|
443
446
|
it 'adds a few more tags to the message' do
|
|
444
447
|
@mb_obj.add_tag('My-Tag-1')
|
|
445
448
|
@mb_obj.add_tag('My-Tag-2')
|
|
446
449
|
@mb_obj.add_tag('My-Tag-3')
|
|
447
450
|
|
|
448
|
-
expect(@mb_obj.message[
|
|
449
|
-
expect(@mb_obj.message[
|
|
450
|
-
expect(@mb_obj.message[
|
|
451
|
+
expect(@mb_obj.message['o:tag'][0]).to eq('My-Tag-1')
|
|
452
|
+
expect(@mb_obj.message['o:tag'][1]).to eq('My-Tag-2')
|
|
453
|
+
expect(@mb_obj.message['o:tag'][2]).to eq('My-Tag-3')
|
|
451
454
|
end
|
|
452
455
|
it 'adds too many tags to the message' do
|
|
453
|
-
expect
|
|
456
|
+
expect do
|
|
454
457
|
12.times do
|
|
455
458
|
@mb_obj.add_tag('My-Tag')
|
|
456
|
-
|
|
459
|
+
end
|
|
460
|
+
end.to raise_error(Mailgun::ParameterError)
|
|
457
461
|
end
|
|
458
462
|
end
|
|
459
463
|
|
|
@@ -472,20 +476,20 @@ describe 'The method track_opens' do
|
|
|
472
476
|
it 'enables/disables open tracking on a per message basis.' do
|
|
473
477
|
@mb_obj.track_opens('Yes')
|
|
474
478
|
|
|
475
|
-
expect(@mb_obj.message[
|
|
476
|
-
expect(@mb_obj.message[
|
|
479
|
+
expect(@mb_obj.message['o:tracking-opens']).to eq('yes')
|
|
480
|
+
expect(@mb_obj.message['o:tracking']).to eq(['yes'])
|
|
477
481
|
|
|
478
482
|
@mb_obj.track_opens('No')
|
|
479
483
|
|
|
480
|
-
expect(@mb_obj.message[
|
|
484
|
+
expect(@mb_obj.message['o:tracking-opens']).to eq('no')
|
|
481
485
|
|
|
482
486
|
@mb_obj.track_opens(true)
|
|
483
487
|
|
|
484
|
-
expect(@mb_obj.message[
|
|
488
|
+
expect(@mb_obj.message['o:tracking-opens']).to eq('yes')
|
|
485
489
|
|
|
486
490
|
@mb_obj.track_opens(false)
|
|
487
491
|
|
|
488
|
-
expect(@mb_obj.message[
|
|
492
|
+
expect(@mb_obj.message['o:tracking-opens']).to eq('no')
|
|
489
493
|
end
|
|
490
494
|
end
|
|
491
495
|
|
|
@@ -504,24 +508,24 @@ describe 'The method track_clicks' do
|
|
|
504
508
|
it 'enables/disables click tracking on a per message basis.' do
|
|
505
509
|
@mb_obj.track_clicks('Yes')
|
|
506
510
|
|
|
507
|
-
expect(@mb_obj.message[
|
|
508
|
-
expect(@mb_obj.message[
|
|
511
|
+
expect(@mb_obj.message['o:tracking-clicks']).to eq('yes')
|
|
512
|
+
expect(@mb_obj.message['o:tracking']).to eq(['yes'])
|
|
509
513
|
|
|
510
514
|
@mb_obj.track_clicks('No')
|
|
511
515
|
|
|
512
|
-
expect(@mb_obj.message[
|
|
516
|
+
expect(@mb_obj.message['o:tracking-clicks']).to eq('no')
|
|
513
517
|
|
|
514
518
|
@mb_obj.track_clicks(true)
|
|
515
519
|
|
|
516
|
-
expect(@mb_obj.message[
|
|
520
|
+
expect(@mb_obj.message['o:tracking-clicks']).to eq('yes')
|
|
517
521
|
|
|
518
522
|
@mb_obj.track_clicks(false)
|
|
519
523
|
|
|
520
|
-
expect(@mb_obj.message[
|
|
524
|
+
expect(@mb_obj.message['o:tracking-clicks']).to eq('no')
|
|
521
525
|
|
|
522
526
|
@mb_obj.track_clicks('html')
|
|
523
527
|
|
|
524
|
-
expect(@mb_obj.message[
|
|
528
|
+
expect(@mb_obj.message['o:tracking-clicks']).to eq('html')
|
|
525
529
|
end
|
|
526
530
|
|
|
527
531
|
context 'when unexpected value is provided' do
|
|
@@ -547,7 +551,7 @@ describe 'The method deliver_at' do
|
|
|
547
551
|
it 'defines a time/date to deliver a message in RFC2822 format.' do
|
|
548
552
|
@mb_obj.deliver_at('October 25, 2013 10:00PM CST')
|
|
549
553
|
|
|
550
|
-
expect(@mb_obj.message[
|
|
554
|
+
expect(@mb_obj.message['o:deliverytime'][0]).to eq('Fri, 25 Oct 2013 22:00:00 -0600')
|
|
551
555
|
end
|
|
552
556
|
end
|
|
553
557
|
|
|
@@ -566,8 +570,8 @@ describe 'The method header' do
|
|
|
566
570
|
it 'accepts valid JSON and appends as data to the message.' do
|
|
567
571
|
@mb_obj.header('my-data', '{"key":"value"}')
|
|
568
572
|
|
|
569
|
-
expect(@mb_obj.message[
|
|
570
|
-
expect(@mb_obj.message[
|
|
573
|
+
expect(@mb_obj.message['h:my-data']).to be_kind_of(String)
|
|
574
|
+
expect(@mb_obj.message['h:my-data'].to_s).to eq('{"key":"value"}')
|
|
571
575
|
end
|
|
572
576
|
end
|
|
573
577
|
|
|
@@ -578,23 +582,23 @@ describe 'The method variable' do
|
|
|
578
582
|
it 'accepts valid JSON and stores it as message[param].' do
|
|
579
583
|
@mb_obj.variable('my-data', '{"key":"value"}')
|
|
580
584
|
|
|
581
|
-
expect(@mb_obj.message[
|
|
582
|
-
expect(@mb_obj.message[
|
|
585
|
+
expect(@mb_obj.message['v:my-data']).to be_kind_of(String)
|
|
586
|
+
expect(@mb_obj.message['v:my-data'].to_s).to eq('{"key":"value"}')
|
|
583
587
|
end
|
|
584
588
|
it 'accepts a hash and appends as data to the message.' do
|
|
585
|
-
data = {'key' => 'value'}
|
|
589
|
+
data = { 'key' => 'value' }
|
|
586
590
|
@mb_obj.variable('my-data', data)
|
|
587
591
|
|
|
588
|
-
expect(@mb_obj.message[
|
|
589
|
-
expect(@mb_obj.message[
|
|
592
|
+
expect(@mb_obj.message['v:my-data']).to be_kind_of(String)
|
|
593
|
+
expect(@mb_obj.message['v:my-data'].to_s).to eq('{"key":"value"}')
|
|
590
594
|
end
|
|
591
595
|
it 'accepts string values' do
|
|
592
596
|
data = 'String Value.'
|
|
593
597
|
|
|
594
598
|
@mb_obj.variable('my-data', data)
|
|
595
599
|
|
|
596
|
-
expect(@mb_obj.message[
|
|
597
|
-
expect(@mb_obj.message[
|
|
600
|
+
expect(@mb_obj.message['v:my-data']).to be_kind_of(String)
|
|
601
|
+
expect(@mb_obj.message['v:my-data'].to_s).to eq('String Value.')
|
|
598
602
|
end
|
|
599
603
|
end
|
|
600
604
|
|
|
@@ -605,7 +609,7 @@ describe 'The method add_custom_parameter' do
|
|
|
605
609
|
it 'adds an undefined parameter to the message.' do
|
|
606
610
|
@mb_obj.add_custom_parameter('h:my-sweet-header', 'datagoeshere')
|
|
607
611
|
|
|
608
|
-
expect(@mb_obj.message[
|
|
612
|
+
expect(@mb_obj.message['h:my-sweet-header'][0]).to eq('datagoeshere')
|
|
609
613
|
end
|
|
610
614
|
end
|
|
611
615
|
|
|
@@ -630,16 +634,16 @@ describe 'The method message_id' do
|
|
|
630
634
|
it 'correctly clears the Message-Id header when passed nil' do
|
|
631
635
|
@mb_obj.message_id(nil)
|
|
632
636
|
|
|
633
|
-
expect(@mb_obj.message.
|
|
637
|
+
expect(@mb_obj.message.key?('h:Message-Id')).to eq(false)
|
|
634
638
|
end
|
|
635
639
|
it 'correctly sets the Message-Id header when passed an empty string' do
|
|
636
640
|
@mb_obj.message_id(@the_message_id)
|
|
637
641
|
|
|
638
|
-
expect(@mb_obj.message.
|
|
642
|
+
expect(@mb_obj.message.key?('h:Message-Id')).to eq(true)
|
|
639
643
|
|
|
640
644
|
@mb_obj.message_id('')
|
|
641
645
|
|
|
642
|
-
expect(@mb_obj.message.
|
|
646
|
+
expect(@mb_obj.message.key?('h:Message-Id')).to eq(false)
|
|
643
647
|
end
|
|
644
648
|
end
|
|
645
649
|
|
|
@@ -672,11 +676,11 @@ describe 'The method template' do
|
|
|
672
676
|
it 'it deletes `template` key from the message' do
|
|
673
677
|
@mb_obj.template('template.name')
|
|
674
678
|
|
|
675
|
-
expect(@mb_obj.message.
|
|
679
|
+
expect(@mb_obj.message.key?('template')).to eq(true)
|
|
676
680
|
|
|
677
681
|
@mb_obj.template
|
|
678
682
|
|
|
679
|
-
expect(@mb_obj.message.
|
|
683
|
+
expect(@mb_obj.message.key?('template')).to eq(false)
|
|
680
684
|
end
|
|
681
685
|
end
|
|
682
686
|
end
|
|
@@ -710,11 +714,11 @@ describe 'The method template_version' do
|
|
|
710
714
|
it 'it deletes `t:version` key from the message' do
|
|
711
715
|
@mb_obj.template_version('version')
|
|
712
716
|
|
|
713
|
-
expect(@mb_obj.message.
|
|
717
|
+
expect(@mb_obj.message.key?('t:version')).to eq(true)
|
|
714
718
|
|
|
715
719
|
@mb_obj.template_version
|
|
716
720
|
|
|
717
|
-
expect(@mb_obj.message.
|
|
721
|
+
expect(@mb_obj.message.key?('t:version')).to eq(false)
|
|
718
722
|
end
|
|
719
723
|
end
|
|
720
724
|
end
|
|
@@ -727,18 +731,18 @@ describe 'The method template_text' do
|
|
|
727
731
|
it 'enables/disables rendering in the text part of the message in case of template sending' do
|
|
728
732
|
@mb_obj.template_text('Yes')
|
|
729
733
|
|
|
730
|
-
expect(@mb_obj.message[
|
|
734
|
+
expect(@mb_obj.message['t:text']).to eq('yes')
|
|
731
735
|
|
|
732
736
|
@mb_obj.template_text('No')
|
|
733
737
|
|
|
734
|
-
expect(@mb_obj.message[
|
|
738
|
+
expect(@mb_obj.message['t:text']).to eq('no')
|
|
735
739
|
|
|
736
740
|
@mb_obj.template_text(true)
|
|
737
741
|
|
|
738
|
-
expect(@mb_obj.message[
|
|
742
|
+
expect(@mb_obj.message['t:text']).to eq('yes')
|
|
739
743
|
|
|
740
744
|
@mb_obj.template_text(false)
|
|
741
745
|
|
|
742
|
-
expect(@mb_obj.message[
|
|
746
|
+
expect(@mb_obj.message['t:text']).to eq('no')
|
|
743
747
|
end
|
|
744
748
|
end
|
|
@@ -1,40 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'spec_helper'
|
|
2
4
|
require 'mailgun'
|
|
3
5
|
require 'railgun'
|
|
4
6
|
|
|
5
7
|
describe 'extract_body' do
|
|
6
|
-
|
|
7
|
-
let(:text_mail_option) {
|
|
8
|
+
let(:text_mail_option) do
|
|
8
9
|
{
|
|
9
|
-
from:
|
|
10
|
-
to:
|
|
11
|
-
subject:
|
|
12
|
-
body:
|
|
13
|
-
content_type: 'text/plain'
|
|
10
|
+
from: 'bob@example.com',
|
|
11
|
+
to: 'sally@example.com',
|
|
12
|
+
subject: 'RAILGUN TEST SAMPLE',
|
|
13
|
+
body: text_content,
|
|
14
|
+
content_type: 'text/plain'
|
|
14
15
|
}
|
|
15
|
-
|
|
16
|
+
end
|
|
16
17
|
let(:text_content) { '[TEST] Hello, world.' }
|
|
17
18
|
|
|
18
|
-
let(:html_mail_option)
|
|
19
|
+
let(:html_mail_option) do
|
|
19
20
|
{
|
|
20
|
-
from:
|
|
21
|
-
to:
|
|
22
|
-
subject:
|
|
23
|
-
body:
|
|
24
|
-
content_type: 'text/html'
|
|
21
|
+
from: 'bob@example.com',
|
|
22
|
+
to: 'sally@example.com',
|
|
23
|
+
subject: 'RAILGUN TEST SAMPLE',
|
|
24
|
+
body: html_content,
|
|
25
|
+
content_type: 'text/html'
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
+
end
|
|
27
28
|
let(:html_content) { '<h3> [TEST] </h3> <br/> Hello, world!' }
|
|
28
29
|
|
|
29
|
-
let(:amp_mail_option)
|
|
30
|
+
let(:amp_mail_option) do
|
|
30
31
|
{
|
|
31
|
-
from:
|
|
32
|
-
to:
|
|
33
|
-
subject:
|
|
34
|
-
body:
|
|
35
|
-
content_type: 'text/x-amp-html'
|
|
32
|
+
from: 'bob@example.com',
|
|
33
|
+
to: 'sally@example.com',
|
|
34
|
+
subject: 'RAILGUN TEST SAMPLE',
|
|
35
|
+
body: amp_content,
|
|
36
|
+
content_type: 'text/x-amp-html'
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
+
end
|
|
38
39
|
let(:amp_content) { '<h3> [TEST] </h3> <br/> Hello from AMP!' }
|
|
39
40
|
|
|
40
41
|
context 'with <Content-Type: text/plain>' do
|
|
@@ -67,7 +68,7 @@ describe 'extract_body' do
|
|
|
67
68
|
let(:amp_mail) { Mail.new(amp_mail_option) }
|
|
68
69
|
|
|
69
70
|
before do
|
|
70
|
-
@sample_mail = Mail::Part.new(content_type:
|
|
71
|
+
@sample_mail = Mail::Part.new(content_type: 'multipart/alternative')
|
|
71
72
|
@sample_mail.add_part text_mail
|
|
72
73
|
@sample_mail.add_part amp_mail
|
|
73
74
|
@sample_mail.add_part html_mail
|