mailgun-ruby 1.1.0 → 1.2.5
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 +5 -5
- data/.gitignore +1 -0
- data/.ruby-env.yml.example +1 -1
- data/.travis.yml +23 -7
- data/Gemfile +2 -0
- data/README.md +79 -18
- data/{Domains.md → docs/Domains.md} +18 -0
- data/{Events.md → docs/Events.md} +0 -0
- data/{MessageBuilder.md → docs/MessageBuilder.md} +32 -13
- data/{Messages.md → docs/Messages.md} +3 -3
- data/{OptInHandler.md → docs/OptInHandler.md} +0 -0
- data/{Snippets.md → docs/Snippets.md} +21 -2
- data/docs/Suppressions.md +82 -0
- data/{Webhooks.md → docs/Webhooks.md} +1 -1
- data/docs/railgun/Overview.md +11 -0
- data/docs/railgun/Parameters.md +83 -0
- data/lib/mailgun/address.rb +48 -0
- data/lib/mailgun/client.rb +85 -8
- data/lib/mailgun/events/events.rb +40 -12
- data/lib/mailgun/exceptions/exceptions.rb +21 -7
- data/lib/mailgun/lists/opt_in_handler.rb +0 -1
- data/lib/mailgun/messages/batch_message.rb +3 -2
- data/lib/mailgun/messages/message_builder.rb +139 -30
- data/lib/mailgun/response.rb +7 -0
- data/lib/mailgun/suppressions.rb +273 -0
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun/webhooks/webhooks.rb +1 -1
- data/lib/mailgun-ruby.rb +2 -0
- data/lib/mailgun.rb +1 -0
- data/lib/railgun/attachment.rb +56 -0
- data/lib/railgun/errors.rb +27 -0
- data/lib/railgun/mailer.rb +253 -0
- data/lib/railgun/message.rb +18 -0
- data/lib/railgun/railtie.rb +10 -0
- data/lib/railgun.rb +8 -0
- data/mailgun.gemspec +12 -13
- data/spec/integration/email_validation_spec.rb +57 -15
- data/spec/integration/events_spec.rb +9 -1
- data/spec/integration/mailer_spec.rb +67 -0
- data/spec/integration/mailgun_spec.rb +51 -1
- data/spec/integration/suppressions_spec.rb +142 -0
- data/spec/spec_helper.rb +3 -1
- data/spec/unit/connection/test_client.rb +16 -0
- data/spec/unit/events/events_spec.rb +36 -2
- data/spec/unit/mailgun_spec.rb +32 -10
- data/spec/unit/messages/batch_message_spec.rb +56 -40
- data/spec/unit/messages/message_builder_spec.rb +267 -81
- data/spec/unit/messages/sample_data/unknown.type +0 -0
- data/spec/unit/railgun/content_type_spec.rb +71 -0
- data/spec/unit/railgun/mailer_spec.rb +388 -0
- data/vcr_cassettes/email_validation.yml +136 -25
- data/vcr_cassettes/events.yml +48 -1
- data/vcr_cassettes/exceptions.yml +45 -0
- data/vcr_cassettes/mailer_invalid_domain.yml +109 -0
- data/vcr_cassettes/message_deliver.yml +149 -0
- data/vcr_cassettes/suppressions.yml +727 -0
- metadata +65 -40
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'stringio'
|
2
3
|
|
3
4
|
describe 'MessageBuilder attribute readers' do
|
4
5
|
it 'should be readable' do
|
5
6
|
@mb_obj = Mailgun::MessageBuilder.new()
|
6
|
-
|
7
|
+
|
7
8
|
expect(@mb_obj).to respond_to(:message)
|
8
9
|
expect(@mb_obj).to respond_to(:counters)
|
9
10
|
end
|
@@ -49,10 +50,20 @@ describe 'The method add_recipient' do
|
|
49
50
|
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1)
|
50
51
|
end
|
51
52
|
|
53
|
+
context 'when variables is empty and recepeint type - "to"' do
|
54
|
+
it 'adds email address as "to" recipient type and increments counter' do
|
55
|
+
recipient_type = :to
|
56
|
+
@mb_obj.add_recipient(recipient_type, @address, {})
|
57
|
+
|
58
|
+
expect(@mb_obj.message[recipient_type][0]).to eq("#{@address}")
|
59
|
+
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
52
63
|
it 'adds a "cc" recipient type to the message body and counter is incremented' do
|
53
64
|
recipient_type = :cc
|
54
65
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
55
|
-
|
66
|
+
|
56
67
|
expect(@mb_obj.message[recipient_type][0]).to eq("'#{@variables['first']} #{@variables['last']}' <#{@address}>")
|
57
68
|
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1)
|
58
69
|
end
|
@@ -60,7 +71,7 @@ describe 'The method add_recipient' do
|
|
60
71
|
it 'adds a "bcc" recipient type to the message body and counter is incremented' do
|
61
72
|
recipient_type = :bcc
|
62
73
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
63
|
-
|
74
|
+
|
64
75
|
expect(@mb_obj.message[recipient_type][0]).to eq("'#{@variables['first']} #{@variables['last']}' <#{@address}>")
|
65
76
|
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1)
|
66
77
|
end
|
@@ -68,21 +79,21 @@ describe 'The method add_recipient' do
|
|
68
79
|
it 'adds a "h:reply-to" recipient type to the message body and counters are not incremented' do
|
69
80
|
recipient_type = 'h:reply-to'
|
70
81
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
71
|
-
|
72
|
-
expect(@mb_obj.message[recipient_type]
|
82
|
+
|
83
|
+
expect(@mb_obj.message[recipient_type]).to eq("'#{@variables['first']} #{@variables['last']}' <#{@address}>")
|
73
84
|
@mb_obj.counters[:recipients].each_value{|value| expect(value).to eq(0)}
|
74
85
|
end
|
75
86
|
|
76
87
|
it 'ensures a random recipient type is added to the message body and counters are not incremented' do
|
77
88
|
recipient_type = 'im-not-really-real'
|
78
89
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
79
|
-
|
90
|
+
|
80
91
|
expect(@mb_obj.message[recipient_type][0]).to eq("'#{@variables['first']} #{@variables['last']}' <#{@address}>")
|
81
92
|
@mb_obj.counters[:recipients].each_value{|value| expect(value).to eq(0)}
|
82
93
|
end
|
83
94
|
it 'adds too many to recipients and raises an exception.' do
|
84
95
|
recipient_type = :to
|
85
|
-
|
96
|
+
|
86
97
|
expect{
|
87
98
|
1001.times do
|
88
99
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
@@ -90,7 +101,7 @@ describe 'The method add_recipient' do
|
|
90
101
|
end
|
91
102
|
it 'adds too many cc recipients and raises an exception.' do
|
92
103
|
recipient_type = :cc
|
93
|
-
|
104
|
+
|
94
105
|
expect{
|
95
106
|
1001.times do
|
96
107
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
@@ -98,7 +109,7 @@ describe 'The method add_recipient' do
|
|
98
109
|
end
|
99
110
|
it 'adds too many bcc recipients and raises an exception.' do
|
100
111
|
recipient_type = :bcc
|
101
|
-
|
112
|
+
|
102
113
|
expect{
|
103
114
|
1001.times do
|
104
115
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
@@ -118,17 +129,17 @@ describe 'The method subject' do
|
|
118
129
|
before(:each) do
|
119
130
|
@mb_obj = Mailgun::MessageBuilder.new
|
120
131
|
end
|
121
|
-
|
132
|
+
|
122
133
|
it 'sets the message subject to blank if called and no parameters are provided' do
|
123
134
|
@mb_obj.subject
|
124
|
-
|
135
|
+
|
125
136
|
expect(@mb_obj.message[:subject][0]).to eq('')
|
126
137
|
end
|
127
|
-
|
138
|
+
|
128
139
|
it 'sets the message subject if called with the subject parameter' do
|
129
140
|
the_subject = 'This is my subject!'
|
130
141
|
@mb_obj.subject(the_subject)
|
131
|
-
|
142
|
+
|
132
143
|
expect(@mb_obj.message[:subject][0]).to eq(the_subject)
|
133
144
|
end
|
134
145
|
|
@@ -137,7 +148,7 @@ describe 'The method subject' do
|
|
137
148
|
the_second_subject = 'This is my second subject!'
|
138
149
|
@mb_obj.subject(the_first_subject)
|
139
150
|
@mb_obj.subject(the_second_subject)
|
140
|
-
|
151
|
+
|
141
152
|
expect(@mb_obj.message[:subject].length).to eq(1)
|
142
153
|
expect(@mb_obj.message[:subject][0]).to eq(the_second_subject)
|
143
154
|
end
|
@@ -169,7 +180,7 @@ describe 'The method body_text' do
|
|
169
180
|
the_second_text = 'Don\'t mess with Texas!'
|
170
181
|
@mb_obj.body_text(the_first_text)
|
171
182
|
@mb_obj.body_text(the_second_text)
|
172
|
-
|
183
|
+
|
173
184
|
expect(@mb_obj.message[:text].length).to eq(1)
|
174
185
|
expect(@mb_obj.message[:text][0]).to eq(the_second_text)
|
175
186
|
end
|
@@ -187,22 +198,37 @@ describe 'The method from' do
|
|
187
198
|
before(:each) do
|
188
199
|
@mb_obj = Mailgun::MessageBuilder.new
|
189
200
|
end
|
190
|
-
|
201
|
+
|
191
202
|
it 'sets the from address' do
|
192
203
|
the_from_address = 'test@mailgun.com'
|
193
204
|
@mb_obj.from(the_from_address)
|
194
|
-
|
205
|
+
|
195
206
|
expect(@mb_obj.message[:from]).to eq([the_from_address])
|
196
207
|
end
|
197
208
|
|
198
|
-
it 'sets the from address with metadata' do
|
209
|
+
it 'sets the from address with first/last metadata' do
|
199
210
|
the_from_address = 'test@mailgun.com'
|
200
211
|
the_first_name = 'Magilla'
|
201
212
|
the_last_name = 'Gorilla'
|
202
213
|
@mb_obj.from(the_from_address, {'first' => the_first_name, 'last' => the_last_name})
|
203
|
-
|
214
|
+
|
204
215
|
expect(@mb_obj.message[:from]).to eq(["'#{the_first_name} #{the_last_name}' <#{the_from_address}>"])
|
205
216
|
end
|
217
|
+
|
218
|
+
it 'sets the from address with full name metadata' do
|
219
|
+
the_from_address = 'test@mailgun.com'
|
220
|
+
full_name = 'Magilla Gorilla'
|
221
|
+
@mb_obj.from(the_from_address, {'full_name' => full_name})
|
222
|
+
|
223
|
+
expect(@mb_obj.message[:from]).to eq(["'#{full_name}' <#{the_from_address}>"])
|
224
|
+
end
|
225
|
+
|
226
|
+
it 'fails when first/last and full_name are used' do
|
227
|
+
the_from_address = 'test@mailgun.com'
|
228
|
+
full_name = 'Magilla Gorilla'
|
229
|
+
first_name = 'Magilla'
|
230
|
+
expect{@mb_obj.from(the_from_address, {'full_name' => full_name, 'first' => first_name})}.to raise_error(Mailgun::ParameterError)
|
231
|
+
end
|
206
232
|
end
|
207
233
|
|
208
234
|
describe 'The method add_attachment' do
|
@@ -217,7 +243,7 @@ describe 'The method add_attachment' do
|
|
217
243
|
file_paths = [file1, file2]
|
218
244
|
|
219
245
|
file_paths.each {|item| @mb_obj.add_attachment(item)}
|
220
|
-
|
246
|
+
|
221
247
|
expect(@mb_obj.message[:attachment].length).to eq(2)
|
222
248
|
end
|
223
249
|
|
@@ -230,6 +256,16 @@ describe 'The method add_attachment' do
|
|
230
256
|
expect(@mb_obj.message[:attachment].length).to eq(1)
|
231
257
|
expect(@mb_obj.message[:attachment].first.original_filename).to eq 'mailgun_icon.png'
|
232
258
|
end
|
259
|
+
|
260
|
+
context 'when attachment has unknown type' do
|
261
|
+
it 'sets content type application/octet-stream for attachment' do
|
262
|
+
file = File.dirname(__FILE__) + "/sample_data/unknown.type"
|
263
|
+
|
264
|
+
@mb_obj.add_attachment(file)
|
265
|
+
|
266
|
+
expect(@mb_obj.message[:attachment][0].content_type).to eq('application/octet-stream')
|
267
|
+
end
|
268
|
+
end
|
233
269
|
end
|
234
270
|
|
235
271
|
describe 'The method add_inline_image' do
|
@@ -243,16 +279,41 @@ describe 'The method add_inline_image' do
|
|
243
279
|
file_paths = [file1, file2]
|
244
280
|
|
245
281
|
file_paths.each {|item| @mb_obj.add_inline_image(item)}
|
246
|
-
|
282
|
+
|
247
283
|
expect(@mb_obj.message[:inline].length).to eq(2)
|
248
284
|
end
|
249
285
|
end
|
250
286
|
|
287
|
+
describe 'The method list_unsubscribe' do
|
288
|
+
before(:each) do
|
289
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
290
|
+
end
|
291
|
+
|
292
|
+
it 'sets the message list_unsubscribe to blank if called and no parameters are provided' do
|
293
|
+
@mb_obj.list_unsubscribe
|
294
|
+
expect(@mb_obj.message['h:List-Unsubscribe']).to eq('')
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'sets the message list_unsubscribe if called with one list_unsubscribe parameter' do
|
298
|
+
unsubscribe_to = 'http://example.com/stop-hassle'
|
299
|
+
@mb_obj.list_unsubscribe(unsubscribe_to)
|
300
|
+
expect(@mb_obj.message['h:List-Unsubscribe']).to eq("<#{unsubscribe_to}>")
|
301
|
+
end
|
302
|
+
|
303
|
+
it 'sets the message list_unsubscribe if called with many list_unsubscribe parameters' do
|
304
|
+
unsubscribe_to = %w(http://example.com/stop-hassle mailto:stop-hassle@example.com)
|
305
|
+
@mb_obj.list_unsubscribe(*unsubscribe_to)
|
306
|
+
expect(@mb_obj.message['h:List-Unsubscribe']).to eq(
|
307
|
+
unsubscribe_to.map { |var| "<#{var}>" }.join(',')
|
308
|
+
)
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
251
312
|
describe 'The method set_test_mode' do
|
252
313
|
it 'warns of set_test_mode deprecation' do
|
253
314
|
@mb_obj = Mailgun::MessageBuilder.new
|
254
315
|
expect(@mb_obj).to receive :warn
|
255
|
-
@mb_obj.set_test_mode '
|
316
|
+
@mb_obj.set_test_mode 'Yes'
|
256
317
|
end
|
257
318
|
end
|
258
319
|
|
@@ -262,29 +323,29 @@ describe 'The method test_mode' do
|
|
262
323
|
end
|
263
324
|
it 'turns on test mode with boolean true' do
|
264
325
|
@mb_obj.test_mode(true)
|
265
|
-
|
326
|
+
|
266
327
|
expect(@mb_obj.message["o:testmode"][0]).to eq("yes")
|
267
328
|
end
|
268
329
|
it 'turns on test mode with string true' do
|
269
330
|
@mb_obj.test_mode("true")
|
270
|
-
|
331
|
+
|
271
332
|
expect(@mb_obj.message["o:testmode"][0]).to eq("yes")
|
272
333
|
end
|
273
334
|
it 'turns off test mode with boolean false' do
|
274
335
|
@mb_obj.test_mode(false)
|
275
|
-
|
336
|
+
|
276
337
|
expect(@mb_obj.message["o:testmode"][0]).to eq("no")
|
277
338
|
end
|
278
339
|
it 'turns off test mode with string false' do
|
279
340
|
@mb_obj.test_mode("false")
|
280
|
-
|
341
|
+
|
281
342
|
expect(@mb_obj.message["o:testmode"][0]).to eq("no")
|
282
343
|
end
|
283
344
|
it 'does not allow multiple values' do
|
284
345
|
@mb_obj.test_mode("false")
|
285
346
|
@mb_obj.test_mode("true")
|
286
347
|
@mb_obj.test_mode("false")
|
287
|
-
|
348
|
+
|
288
349
|
expect(@mb_obj.message["o:testmode"].length).to eq(1)
|
289
350
|
expect(@mb_obj.message["o:testmode"][0]).to eq("no")
|
290
351
|
end
|
@@ -294,7 +355,7 @@ describe 'The method set_dkim' do
|
|
294
355
|
it 'warns of set_dkim deprecation' do
|
295
356
|
@mb_obj = Mailgun::MessageBuilder.new
|
296
357
|
expect(@mb_obj).to receive :warn
|
297
|
-
@mb_obj.set_dkim '
|
358
|
+
@mb_obj.set_dkim 'Yes'
|
298
359
|
end
|
299
360
|
end
|
300
361
|
|
@@ -304,29 +365,29 @@ describe 'The method dkim' do
|
|
304
365
|
end
|
305
366
|
it 'turns on dkim with boolean true' do
|
306
367
|
@mb_obj.dkim(true)
|
307
|
-
|
368
|
+
|
308
369
|
expect(@mb_obj.message["o:dkim"][0]).to eq("yes")
|
309
370
|
end
|
310
371
|
it 'turns on dkim with string true' do
|
311
372
|
@mb_obj.dkim("true")
|
312
|
-
|
373
|
+
|
313
374
|
expect(@mb_obj.message["o:dkim"][0]).to eq("yes")
|
314
375
|
end
|
315
376
|
it 'turns off dkim with boolean false' do
|
316
377
|
@mb_obj.dkim(false)
|
317
|
-
|
378
|
+
|
318
379
|
expect(@mb_obj.message["o:dkim"][0]).to eq("no")
|
319
380
|
end
|
320
381
|
it 'turns off dkim with string false' do
|
321
382
|
@mb_obj.dkim("false")
|
322
|
-
|
383
|
+
|
323
384
|
expect(@mb_obj.message["o:dkim"][0]).to eq("no")
|
324
385
|
end
|
325
386
|
it 'does not allow multiple values' do
|
326
387
|
@mb_obj.dkim("false")
|
327
388
|
@mb_obj.dkim("true")
|
328
389
|
@mb_obj.dkim("false")
|
329
|
-
|
390
|
+
|
330
391
|
expect(@mb_obj.message["o:dkim"].length).to eq(1)
|
331
392
|
expect(@mb_obj.message["o:dkim"][0]).to eq("no")
|
332
393
|
end
|
@@ -338,14 +399,14 @@ describe 'The method add_campaign_id' do
|
|
338
399
|
end
|
339
400
|
it 'adds a campaign ID to the message' do
|
340
401
|
@mb_obj.add_campaign_id('My-Campaign-Id-1')
|
341
|
-
|
402
|
+
|
342
403
|
expect(@mb_obj.message["o:campaign"][0]).to eq ("My-Campaign-Id-1")
|
343
404
|
end
|
344
405
|
it 'adds a few more campaign IDs to the message' do
|
345
406
|
@mb_obj.add_campaign_id('My-Campaign-Id-1')
|
346
407
|
@mb_obj.add_campaign_id('My-Campaign-Id-2')
|
347
408
|
@mb_obj.add_campaign_id('My-Campaign-Id-3')
|
348
|
-
|
409
|
+
|
349
410
|
expect(@mb_obj.message["o:campaign"][0]).to eq("My-Campaign-Id-1")
|
350
411
|
expect(@mb_obj.message["o:campaign"][1]).to eq("My-Campaign-Id-2")
|
351
412
|
expect(@mb_obj.message["o:campaign"][2]).to eq("My-Campaign-Id-3")
|
@@ -364,14 +425,14 @@ describe 'The method add_tag' do
|
|
364
425
|
end
|
365
426
|
it 'adds a tag to the message' do
|
366
427
|
@mb_obj.add_tag('My-Tag-1')
|
367
|
-
|
428
|
+
|
368
429
|
expect(@mb_obj.message["o:tag"][0]).to eq("My-Tag-1")
|
369
430
|
end
|
370
431
|
it 'adds a few more tags to the message' do
|
371
432
|
@mb_obj.add_tag('My-Tag-1')
|
372
433
|
@mb_obj.add_tag('My-Tag-2')
|
373
434
|
@mb_obj.add_tag('My-Tag-3')
|
374
|
-
|
435
|
+
|
375
436
|
expect(@mb_obj.message["o:tag"][0]).to eq("My-Tag-1")
|
376
437
|
expect(@mb_obj.message["o:tag"][1]).to eq("My-Tag-2")
|
377
438
|
expect(@mb_obj.message["o:tag"][2]).to eq("My-Tag-3")
|
@@ -388,7 +449,7 @@ describe 'The method set_open_tracking' do
|
|
388
449
|
it 'warns of set_open_tracking deprecation' do
|
389
450
|
@mb_obj = Mailgun::MessageBuilder.new
|
390
451
|
expect(@mb_obj).to receive :warn
|
391
|
-
@mb_obj.set_open_tracking '
|
452
|
+
@mb_obj.set_open_tracking 'Yes'
|
392
453
|
end
|
393
454
|
end
|
394
455
|
|
@@ -398,20 +459,21 @@ describe 'The method track_opens' do
|
|
398
459
|
end
|
399
460
|
it 'enables/disables open tracking on a per message basis.' do
|
400
461
|
@mb_obj.track_opens('Yes')
|
401
|
-
|
402
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
403
|
-
|
462
|
+
|
463
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("yes")
|
464
|
+
expect(@mb_obj.message["o:tracking"]).to eq(["yes"])
|
465
|
+
|
404
466
|
@mb_obj.track_opens('No')
|
405
|
-
|
406
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
407
|
-
|
467
|
+
|
468
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("no")
|
469
|
+
|
408
470
|
@mb_obj.track_opens(true)
|
409
|
-
|
410
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
411
|
-
|
471
|
+
|
472
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("yes")
|
473
|
+
|
412
474
|
@mb_obj.track_opens(false)
|
413
|
-
|
414
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
475
|
+
|
476
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("no")
|
415
477
|
end
|
416
478
|
end
|
417
479
|
|
@@ -419,7 +481,7 @@ describe 'The method set_click_tracking' do
|
|
419
481
|
it 'warns of set_click_tracking deprecation' do
|
420
482
|
@mb_obj = Mailgun::MessageBuilder.new
|
421
483
|
expect(@mb_obj).to receive :warn
|
422
|
-
@mb_obj.set_click_tracking '
|
484
|
+
@mb_obj.set_click_tracking 'Yes'
|
423
485
|
end
|
424
486
|
end
|
425
487
|
|
@@ -429,24 +491,32 @@ describe 'The method track_clicks' do
|
|
429
491
|
end
|
430
492
|
it 'enables/disables click tracking on a per message basis.' do
|
431
493
|
@mb_obj.track_clicks('Yes')
|
432
|
-
|
433
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
434
|
-
|
494
|
+
|
495
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("yes")
|
496
|
+
expect(@mb_obj.message["o:tracking"]).to eq(["yes"])
|
497
|
+
|
435
498
|
@mb_obj.track_clicks('No')
|
436
|
-
|
437
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
438
|
-
|
499
|
+
|
500
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("no")
|
501
|
+
|
439
502
|
@mb_obj.track_clicks(true)
|
440
|
-
|
441
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
442
|
-
|
503
|
+
|
504
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("yes")
|
505
|
+
|
443
506
|
@mb_obj.track_clicks(false)
|
444
|
-
|
445
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
446
|
-
|
507
|
+
|
508
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("no")
|
509
|
+
|
447
510
|
@mb_obj.track_clicks('html')
|
448
|
-
|
449
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
511
|
+
|
512
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("html")
|
513
|
+
end
|
514
|
+
|
515
|
+
context 'when unexpected value is provided' do
|
516
|
+
it 'warns about prefered values' do
|
517
|
+
expect(@mb_obj).to receive :warn
|
518
|
+
@mb_obj.track_clicks('random')
|
519
|
+
end
|
450
520
|
end
|
451
521
|
end
|
452
522
|
|
@@ -464,7 +534,7 @@ describe 'The method deliver_at' do
|
|
464
534
|
end
|
465
535
|
it 'defines a time/date to deliver a message in RFC2822 format.' do
|
466
536
|
@mb_obj.deliver_at('October 25, 2013 10:00PM CST')
|
467
|
-
|
537
|
+
|
468
538
|
expect(@mb_obj.message["o:deliverytime"][0]).to eq("Fri, 25 Oct 2013 22:00:00 -0600")
|
469
539
|
end
|
470
540
|
end
|
@@ -483,20 +553,36 @@ describe 'The method header' do
|
|
483
553
|
end
|
484
554
|
it 'accepts valid JSON and appends as data to the message.' do
|
485
555
|
@mb_obj.header('my-data', '{"key":"value"}')
|
486
|
-
|
487
|
-
expect(@mb_obj.message["
|
488
|
-
expect(@mb_obj.message["
|
556
|
+
|
557
|
+
expect(@mb_obj.message["h:my-data"]).to be_kind_of(String)
|
558
|
+
expect(@mb_obj.message["h:my-data"].to_s).to eq('{"key":"value"}')
|
559
|
+
end
|
560
|
+
end
|
561
|
+
|
562
|
+
describe 'The method variable' do
|
563
|
+
before(:each) do
|
564
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
565
|
+
end
|
566
|
+
it 'accepts valid JSON and stores it as message[param].' do
|
567
|
+
@mb_obj.variable('my-data', '{"key":"value"}')
|
568
|
+
|
569
|
+
expect(@mb_obj.message["v:my-data"]).to be_kind_of(String)
|
570
|
+
expect(@mb_obj.message["v:my-data"].to_s).to eq('{"key":"value"}')
|
489
571
|
end
|
490
572
|
it 'accepts a hash and appends as data to the message.' do
|
491
573
|
data = {'key' => 'value'}
|
492
|
-
@mb_obj.
|
493
|
-
|
494
|
-
expect(@mb_obj.message["v:my-data"]
|
495
|
-
expect(@mb_obj.message["v:my-data"]
|
574
|
+
@mb_obj.variable('my-data', data)
|
575
|
+
|
576
|
+
expect(@mb_obj.message["v:my-data"]).to be_kind_of(String)
|
577
|
+
expect(@mb_obj.message["v:my-data"].to_s).to eq('{"key":"value"}')
|
496
578
|
end
|
497
|
-
it '
|
498
|
-
data = '
|
499
|
-
|
579
|
+
it 'accepts string values' do
|
580
|
+
data = 'String Value.'
|
581
|
+
|
582
|
+
@mb_obj.variable('my-data', data)
|
583
|
+
|
584
|
+
expect(@mb_obj.message["v:my-data"]).to be_kind_of(String)
|
585
|
+
expect(@mb_obj.message["v:my-data"].to_s).to eq('String Value.')
|
500
586
|
end
|
501
587
|
end
|
502
588
|
|
@@ -506,7 +592,7 @@ describe 'The method add_custom_parameter' do
|
|
506
592
|
end
|
507
593
|
it 'adds an undefined parameter to the message.' do
|
508
594
|
@mb_obj.add_custom_parameter('h:my-sweet-header', 'datagoeshere')
|
509
|
-
|
595
|
+
|
510
596
|
expect(@mb_obj.message["h:my-sweet-header"][0]).to eq("datagoeshere")
|
511
597
|
end
|
512
598
|
end
|
@@ -526,21 +612,121 @@ describe 'The method message_id' do
|
|
526
612
|
end
|
527
613
|
it 'correctly sets the Message-Id header' do
|
528
614
|
@mb_obj.message_id(@the_message_id)
|
529
|
-
|
615
|
+
|
530
616
|
expect(@mb_obj.message['h:Message-Id']).to eq(@the_message_id)
|
531
617
|
end
|
532
618
|
it 'correctly clears the Message-Id header when passed nil' do
|
533
619
|
@mb_obj.message_id(nil)
|
534
|
-
|
620
|
+
|
535
621
|
expect(@mb_obj.message.has_key?('h:Message-Id')).to eq(false)
|
536
622
|
end
|
537
623
|
it 'correctly sets the Message-Id header when passed an empty string' do
|
538
624
|
@mb_obj.message_id(@the_message_id)
|
539
|
-
|
625
|
+
|
540
626
|
expect(@mb_obj.message.has_key?('h:Message-Id')).to eq(true)
|
541
|
-
|
627
|
+
|
542
628
|
@mb_obj.message_id('')
|
543
|
-
|
629
|
+
|
544
630
|
expect(@mb_obj.message.has_key?('h:Message-Id')).to eq(false)
|
545
631
|
end
|
546
632
|
end
|
633
|
+
|
634
|
+
describe 'The method template' do
|
635
|
+
before(:each) do
|
636
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
637
|
+
end
|
638
|
+
context 'when template name is passed' do
|
639
|
+
it 'sets `template` to the message' do
|
640
|
+
template_name = 'template.name'
|
641
|
+
@mb_obj.template(template_name)
|
642
|
+
|
643
|
+
expect(@mb_obj.message['template']).to eq(template_name)
|
644
|
+
end
|
645
|
+
end
|
646
|
+
|
647
|
+
context 'when multiple values are passed' do
|
648
|
+
it 'sets the last value as message template' do
|
649
|
+
template_name_1 = 'template.name_1'
|
650
|
+
template_name_2 = 'template.name_2'
|
651
|
+
|
652
|
+
@mb_obj.template(template_name_1)
|
653
|
+
@mb_obj.template(template_name_2)
|
654
|
+
|
655
|
+
expect(@mb_obj.message['template']).to eq(template_name_2)
|
656
|
+
end
|
657
|
+
end
|
658
|
+
|
659
|
+
context 'when template name is not passed' do
|
660
|
+
it 'it deletes `template` key from the message' do
|
661
|
+
@mb_obj.template('template.name')
|
662
|
+
|
663
|
+
expect(@mb_obj.message.has_key?('template')).to eq(true)
|
664
|
+
|
665
|
+
@mb_obj.template
|
666
|
+
|
667
|
+
expect(@mb_obj.message.has_key?('template')).to eq(false)
|
668
|
+
end
|
669
|
+
end
|
670
|
+
end
|
671
|
+
|
672
|
+
describe 'The method template_version' do
|
673
|
+
before(:each) do
|
674
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
675
|
+
end
|
676
|
+
context 'when template version is passed' do
|
677
|
+
it 'adds `t:version` key value to the message' do
|
678
|
+
version = 'version_1'
|
679
|
+
@mb_obj.template_version(version)
|
680
|
+
|
681
|
+
expect(@mb_obj.message['t:version']).to eq(version)
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|
685
|
+
context 'when multiple values are passed' do
|
686
|
+
it 'adds the last value as `t:version` key value to the message' do
|
687
|
+
version_1 = 'version_1'
|
688
|
+
version_2 = 'version_2'
|
689
|
+
|
690
|
+
@mb_obj.template_version(version_1)
|
691
|
+
@mb_obj.template_version(version_2)
|
692
|
+
|
693
|
+
expect(@mb_obj.message['t:version']).to eq(version_2)
|
694
|
+
end
|
695
|
+
end
|
696
|
+
|
697
|
+
context 'when version is not passed' do
|
698
|
+
it 'it deletes `t:version` key from the message' do
|
699
|
+
@mb_obj.template_version('version')
|
700
|
+
|
701
|
+
expect(@mb_obj.message.has_key?('t:version')).to eq(true)
|
702
|
+
|
703
|
+
@mb_obj.template_version
|
704
|
+
|
705
|
+
expect(@mb_obj.message.has_key?('t:version')).to eq(false)
|
706
|
+
end
|
707
|
+
end
|
708
|
+
end
|
709
|
+
|
710
|
+
describe 'The method template_text' do
|
711
|
+
before(:each) do
|
712
|
+
@mb_obj = Mailgun::MessageBuilder.new
|
713
|
+
end
|
714
|
+
|
715
|
+
it 'enables/disables rendering in the text part of the message in case of template sending' do
|
716
|
+
@mb_obj.template_text('Yes')
|
717
|
+
|
718
|
+
expect(@mb_obj.message["t:text"]).to eq("yes")
|
719
|
+
|
720
|
+
@mb_obj.template_text('No')
|
721
|
+
|
722
|
+
expect(@mb_obj.message["t:text"]).to eq("no")
|
723
|
+
|
724
|
+
@mb_obj.template_text(true)
|
725
|
+
|
726
|
+
expect(@mb_obj.message["t:text"]).to eq("yes")
|
727
|
+
|
728
|
+
@mb_obj.template_text(false)
|
729
|
+
|
730
|
+
expect(@mb_obj.message["t:text"]).to eq("no")
|
731
|
+
end
|
732
|
+
end
|
File without changes
|