mailgun-ruby 1.2.0 → 1.2.10
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/README.md +9 -1
- data/docs/Domains.md +3 -0
- data/docs/OptInHandler.md +1 -1
- data/docs/Snippets.md +54 -61
- data/docs/railgun/Templates.md +92 -0
- data/lib/mailgun/address.rb +3 -28
- data/lib/mailgun/client.rb +43 -10
- data/lib/mailgun/domains/domains.rb +19 -1
- data/lib/mailgun/exceptions/exceptions.rb +28 -1
- data/lib/mailgun/messages/batch_message.rb +1 -0
- data/lib/mailgun/messages/message_builder.rb +55 -7
- data/lib/mailgun/suppressions.rb +15 -8
- data/lib/mailgun/version.rb +1 -1
- data/lib/mailgun-ruby.rb +1 -1
- data/lib/mailgun.rb +3 -1
- data/lib/railgun/mailer.rb +30 -9
- data/lib/railgun/message.rb +2 -1
- data/lib/railgun/railtie.rb +3 -2
- data/mailgun.gemspec +1 -1
- data/spec/integration/bounces_spec.rb +3 -3
- data/spec/integration/domains_spec.rb +8 -0
- data/spec/integration/email_validation_spec.rb +1 -8
- data/spec/integration/mailer_spec.rb +67 -0
- data/spec/integration/mailgun_spec.rb +76 -1
- data/spec/integration/suppressions_spec.rb +18 -2
- data/spec/unit/connection/test_client.rb +18 -1
- data/spec/unit/mailgun_spec.rb +43 -2
- data/spec/unit/messages/batch_message_spec.rb +56 -40
- data/spec/unit/messages/message_builder_spec.rb +149 -16
- data/spec/unit/messages/sample_data/unknown.type +0 -0
- data/spec/unit/railgun/mailer_spec.rb +171 -0
- data/vcr_cassettes/bounces.yml +12 -12
- data/vcr_cassettes/domains.yml +51 -1
- data/vcr_cassettes/exceptions-invalid-api-key.yml +52 -0
- data/vcr_cassettes/exceptions-invalid-data.yml +52 -0
- data/vcr_cassettes/exceptions-not-allowed.yml +54 -0
- data/vcr_cassettes/mailer_invalid_domain.yml +109 -0
- data/vcr_cassettes/message_deliver.yml +149 -0
- data/vcr_cassettes/suppressions.yml +66 -15
- metadata +15 -6
@@ -34,6 +34,78 @@ describe 'Client exceptions', vcr: vcr_opts do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
vcr_opts = { :cassette_name => "exceptions-invalid-api-key" }
|
38
|
+
|
39
|
+
describe 'Client exceptions', vcr: vcr_opts do
|
40
|
+
before(:all) do
|
41
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
42
|
+
@domain = TESTDOMAIN
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'displays error information that API key is invalid' do
|
46
|
+
begin
|
47
|
+
@mg_obj.send_message(@domain, {
|
48
|
+
:from => "sally@#{@domain}",
|
49
|
+
:to => "sally@#{@domain}",
|
50
|
+
:subject => 'Exception Integration Test',
|
51
|
+
:text => 'INTEGRATION TESTING'
|
52
|
+
})
|
53
|
+
rescue Mailgun::Unauthorized => err
|
54
|
+
expect(err.message).to eq('401 Unauthorized - Invalid Domain or API key: Forbidden')
|
55
|
+
else
|
56
|
+
fail
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
vcr_opts = { :cassette_name => "exceptions-invalid-data" }
|
62
|
+
|
63
|
+
describe 'Client exceptions', vcr: vcr_opts do
|
64
|
+
before(:all) do
|
65
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
66
|
+
@domain = TESTDOMAIN
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'display useful error information' do
|
70
|
+
begin
|
71
|
+
@mg_obj.send_message(@domain, {
|
72
|
+
:from => "sally@#{@domain}",
|
73
|
+
:to => "sally#{@domain}",
|
74
|
+
:subject => 'Exception Integration Test',
|
75
|
+
:text => 'INTEGRATION TESTING'
|
76
|
+
})
|
77
|
+
rescue Mailgun::BadRequest => err
|
78
|
+
expect(err.message).to eq('400 Bad Request: to parameter is not a valid address. please check documentation')
|
79
|
+
else
|
80
|
+
fail
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
vcr_opts = { :cassette_name => "exceptions-not-allowed" }
|
86
|
+
|
87
|
+
describe 'Client exceptions', vcr: vcr_opts do
|
88
|
+
before(:all) do
|
89
|
+
@mg_obj = Mailgun::Client.new(APIKEY, APIHOST, APIVERSION, SSL)
|
90
|
+
@domain = TESTDOMAIN
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'display useful error information' do
|
94
|
+
begin
|
95
|
+
@mg_obj.send_message(@domain, {
|
96
|
+
:from => "invalid@#{@domain}",
|
97
|
+
:to => "invalid#{@domain}",
|
98
|
+
:subject => 'Exception Integration Test',
|
99
|
+
:text => 'INTEGRATION TESTING'
|
100
|
+
})
|
101
|
+
rescue Mailgun::CommunicationError => err
|
102
|
+
expect(err.message).to include('403 Forbidden')
|
103
|
+
else
|
104
|
+
fail
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
37
109
|
vcr_opts = { :cassette_name => "send_message" }
|
38
110
|
|
39
111
|
describe 'The method send_message()', vcr: vcr_opts do
|
@@ -63,6 +135,9 @@ describe 'The method send_message()', vcr: vcr_opts do
|
|
63
135
|
:to => "bob@#{@domain}",
|
64
136
|
:subject => "Test",
|
65
137
|
:text => "Test Data" }
|
138
|
+
uuid = 'uuid'
|
139
|
+
|
140
|
+
allow(SecureRandom).to receive(:uuid).and_return(uuid)
|
66
141
|
|
67
142
|
result = @mg_obj.send_message(@domain, data)
|
68
143
|
|
@@ -72,7 +147,7 @@ describe 'The method send_message()', vcr: vcr_opts do
|
|
72
147
|
expect(result.body).to include("id")
|
73
148
|
|
74
149
|
expect(result.code).to eq(200)
|
75
|
-
expect(result.body['id']).to eq("test-mode-mail@localhost")
|
150
|
+
expect(result.body['id']).to eq("test-mode-mail-#{uuid}@localhost")
|
76
151
|
expect(result.body['message']).to eq("Queued. Thank you.")
|
77
152
|
end
|
78
153
|
|
@@ -52,7 +52,7 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
it 'can batch-add unsubscribes' do
|
55
|
+
it 'can batch-add unsubscribes with tags as string' do
|
56
56
|
unsubscribes = []
|
57
57
|
@addresses.each do |addr|
|
58
58
|
unsubscribes.push({
|
@@ -69,6 +69,23 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
69
69
|
expect(nested.length).to eq(0)
|
70
70
|
end
|
71
71
|
|
72
|
+
it 'can batch-add unsubscribes with tags as array' do
|
73
|
+
unsubscribes = []
|
74
|
+
@addresses.each do |addr|
|
75
|
+
unsubscribes.push({
|
76
|
+
:address => addr,
|
77
|
+
:tags => ['integration'],
|
78
|
+
})
|
79
|
+
end
|
80
|
+
|
81
|
+
response, nested = @suppress.create_unsubscribes unsubscribes
|
82
|
+
response.to_h!
|
83
|
+
|
84
|
+
expect(response.code).to eq(200)
|
85
|
+
expect(response.body['message']).to eq('4 addresses have been added to the unsubscribes table')
|
86
|
+
expect(nested.length).to eq(0)
|
87
|
+
end
|
88
|
+
|
72
89
|
it 'raises ParameterError if no unsubscribe[:address] is present' do
|
73
90
|
unsubscribes = []
|
74
91
|
unsubscribes.push({
|
@@ -123,4 +140,3 @@ describe 'For the suppressions handling class', order: :defined, vcr: vcr_opts d
|
|
123
140
|
|
124
141
|
# TODO: Add tests for pagination support.
|
125
142
|
end
|
126
|
-
|
@@ -23,6 +23,7 @@ module Mailgun
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def send_message(working_domain, data)
|
26
|
+
perform_data_validation(working_domain, data)
|
26
27
|
case data
|
27
28
|
when Hash
|
28
29
|
if data.has_key?(:message)
|
@@ -45,7 +46,8 @@ module Mailgun
|
|
45
46
|
Mailgun::Response.new(response_generator(@endpoint))
|
46
47
|
rescue => e
|
47
48
|
p e
|
48
|
-
raise CommunicationError.new(e), e.response
|
49
|
+
raise CommunicationError.new(e), e.response if e.respond_to? :response
|
50
|
+
raise CommunicationError.new(e.message)
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
@@ -75,6 +77,21 @@ module Mailgun
|
|
75
77
|
|
76
78
|
private
|
77
79
|
|
80
|
+
def perform_data_validation(working_domain, data)
|
81
|
+
fail ParameterError.new('Missing working domain', working_domain) unless working_domain
|
82
|
+
return true unless data.is_a?(Hash) && data.present?
|
83
|
+
message = data.respond_to?(:message) ? data.message : data
|
84
|
+
|
85
|
+
fail ParameterError.new(
|
86
|
+
'Missing `to` recipient, message should containg at least 1 recipient',
|
87
|
+
working_domain
|
88
|
+
) if message.fetch('to', []).empty? && message.fetch(:to, []).empty?
|
89
|
+
fail ParameterError.new(
|
90
|
+
'Missing a `from` sender, message should containg at least 1 `from` sender',
|
91
|
+
working_domain
|
92
|
+
) if message.fetch('from', []).empty? && message.fetch(:from, []).empty?
|
93
|
+
end
|
94
|
+
|
78
95
|
def response_generator(resource_endpoint)
|
79
96
|
if resource_endpoint == "messages"
|
80
97
|
t = Time.now
|
data/spec/unit/mailgun_spec.rb
CHANGED
@@ -37,8 +37,11 @@ describe 'The method send_message()' do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'opens the message MIME and sends the MIME message.' do
|
40
|
-
data = {
|
41
|
-
|
40
|
+
data = {
|
41
|
+
'to' => 'joe@test.com',
|
42
|
+
'message' => 'Sample Data/mime.txt',
|
43
|
+
'from' => 'joe@test.com'
|
44
|
+
}
|
42
45
|
result = @mg_obj.send_message("testdomain.com", data)
|
43
46
|
|
44
47
|
result.to_h!
|
@@ -46,6 +49,25 @@ describe 'The method send_message()' do
|
|
46
49
|
expect(result.body).to include("message")
|
47
50
|
expect(result.body).to include("id")
|
48
51
|
end
|
52
|
+
|
53
|
+
context 'when domain is missing' do
|
54
|
+
it 'shows failure message' do
|
55
|
+
expect(@mg_obj).to receive(:fail)
|
56
|
+
@mg_obj.send_message(nil, {})
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'when to is missing' do
|
61
|
+
it 'shows failure message' do
|
62
|
+
data = {
|
63
|
+
'to' => '',
|
64
|
+
'message' => 'Sample Data/mime.txt',
|
65
|
+
'from' => 'joe@test.com'
|
66
|
+
}
|
67
|
+
expect(@mg_obj).to receive(:fail)
|
68
|
+
@mg_obj.send_message("testdomain.com", data)
|
69
|
+
end
|
70
|
+
end
|
49
71
|
end
|
50
72
|
|
51
73
|
describe 'The method post()' do
|
@@ -65,6 +87,25 @@ describe 'The method post()' do
|
|
65
87
|
expect(result.body).to include("message")
|
66
88
|
expect(result.body).to include("id")
|
67
89
|
end
|
90
|
+
|
91
|
+
context 'when Unknown API error is raised' do
|
92
|
+
before do
|
93
|
+
allow(Mailgun::Response).to receive(:new).and_raise(StandardError, "message")
|
94
|
+
allow(JSON).to receive(:parse).and_raise('Unknown')
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'adds Unknown API error to message' do
|
98
|
+
data = {'from' => 'joe@test.com',
|
99
|
+
'to' => 'bob@example.com',
|
100
|
+
'subject' => 'Test',
|
101
|
+
'text' => 'Test Data'}
|
102
|
+
@mg_obj.post("#{@domain}/messages", data)
|
103
|
+
rescue Mailgun::CommunicationError => err
|
104
|
+
expect(err.message).to eq('message: Unknown API error')
|
105
|
+
else
|
106
|
+
fail
|
107
|
+
end
|
108
|
+
end
|
68
109
|
end
|
69
110
|
|
70
111
|
describe 'The method put()' do
|
@@ -72,60 +72,76 @@ describe 'The method add_recipient' do
|
|
72
72
|
@address_3 = 'sam@example.com'
|
73
73
|
@variables_3 = {'first' => 'Sam', 'last' => 'Doe', 'tracking' => 'GHI123'}
|
74
74
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
1000.times do
|
79
|
-
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
75
|
+
context 'when from is present' do
|
76
|
+
before(:each) do
|
77
|
+
@mb_obj.from('example@email.com')
|
80
78
|
end
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
end
|
80
|
+
it 'adds 1,000 recipients to the message body and validates counter is incremented then reset' do
|
81
|
+
recipient_type = :to
|
82
|
+
1000.times do
|
83
|
+
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
84
|
+
end
|
88
85
|
|
89
|
-
|
90
|
-
|
91
|
-
1000.times do
|
86
|
+
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1000)
|
87
|
+
|
92
88
|
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
89
|
+
|
90
|
+
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1)
|
93
91
|
end
|
94
92
|
|
95
|
-
|
96
|
-
|
93
|
+
it 'adds recipients to the message, calls finalize, and cleans up' do
|
94
|
+
recipient_type = :to
|
95
|
+
1000.times do
|
96
|
+
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
97
|
+
end
|
97
98
|
|
98
|
-
|
99
|
-
|
100
|
-
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(0)
|
101
|
-
end
|
99
|
+
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1000)
|
100
|
+
@mb_obj.finalize
|
102
101
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
@mb_obj.
|
102
|
+
expect(@mb_obj.recipient_variables).to eq({})
|
103
|
+
expect(@mb_obj.message['recipient-variables'].length).to eq(0)
|
104
|
+
expect(@mb_obj.message[:to].length).to eq(0)
|
105
|
+
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(0)
|
107
106
|
end
|
108
|
-
@mb_obj.finalize
|
109
107
|
|
110
|
-
|
111
|
-
|
108
|
+
it 'adds 5,005 recipients to the message body and validates we receive message_ids back' do
|
109
|
+
recipient_type = :to
|
110
|
+
5005.times do
|
111
|
+
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
112
|
+
end
|
113
|
+
@mb_obj.finalize
|
112
114
|
|
113
|
-
|
114
|
-
|
115
|
-
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
115
|
+
expect(@mb_obj.message_ids.length).to eq(6)
|
116
|
+
end
|
116
117
|
|
117
|
-
|
118
|
+
it 'sets recipient-variables, for batch expansion' do
|
119
|
+
recipient_type = :to
|
120
|
+
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
121
|
+
|
122
|
+
expect(@mb_obj.recipient_variables[@address_1]).to eq(@variables_1)
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'sets multiple recipient-variables, for batch expansion' do
|
126
|
+
recipient_type = :to
|
127
|
+
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
128
|
+
@mb_obj.add_recipient(recipient_type, @address_2, @variables_2)
|
129
|
+
@mb_obj.add_recipient(recipient_type, @address_3, @variables_3)
|
130
|
+
|
131
|
+
expect(@mb_obj.recipient_variables[@address_1]).to eq(@variables_1)
|
132
|
+
expect(@mb_obj.recipient_variables[@address_2]).to eq(@variables_2)
|
133
|
+
expect(@mb_obj.recipient_variables[@address_3]).to eq(@variables_3)
|
134
|
+
end
|
118
135
|
end
|
119
136
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
expect(@mb_obj.recipient_variables[@address_3]).to eq(@variables_3)
|
137
|
+
context 'when from is empty' do
|
138
|
+
it 'shows error message' do
|
139
|
+
recipient_type = :to
|
140
|
+
@mb_obj.add_recipient(recipient_type, @address_1, @variables_1)
|
141
|
+
@mb_obj.add_recipient(recipient_type, @address_2, @variables_2)
|
142
|
+
expect(@mb_client).to receive(:fail)
|
143
|
+
@mb_obj.finalize
|
144
|
+
end
|
129
145
|
end
|
130
146
|
|
131
147
|
end
|
@@ -50,6 +50,16 @@ describe 'The method add_recipient' do
|
|
50
50
|
expect(@mb_obj.counters[:recipients][recipient_type]).to eq(1)
|
51
51
|
end
|
52
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
|
+
|
53
63
|
it 'adds a "cc" recipient type to the message body and counter is incremented' do
|
54
64
|
recipient_type = :cc
|
55
65
|
@mb_obj.add_recipient(recipient_type, @address, @variables)
|
@@ -246,6 +256,16 @@ describe 'The method add_attachment' do
|
|
246
256
|
expect(@mb_obj.message[:attachment].length).to eq(1)
|
247
257
|
expect(@mb_obj.message[:attachment].first.original_filename).to eq 'mailgun_icon.png'
|
248
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
|
249
269
|
end
|
250
270
|
|
251
271
|
describe 'The method add_inline_image' do
|
@@ -293,7 +313,7 @@ describe 'The method set_test_mode' do
|
|
293
313
|
it 'warns of set_test_mode deprecation' do
|
294
314
|
@mb_obj = Mailgun::MessageBuilder.new
|
295
315
|
expect(@mb_obj).to receive :warn
|
296
|
-
@mb_obj.set_test_mode '
|
316
|
+
@mb_obj.set_test_mode 'Yes'
|
297
317
|
end
|
298
318
|
end
|
299
319
|
|
@@ -335,7 +355,7 @@ describe 'The method set_dkim' do
|
|
335
355
|
it 'warns of set_dkim deprecation' do
|
336
356
|
@mb_obj = Mailgun::MessageBuilder.new
|
337
357
|
expect(@mb_obj).to receive :warn
|
338
|
-
@mb_obj.set_dkim '
|
358
|
+
@mb_obj.set_dkim 'Yes'
|
339
359
|
end
|
340
360
|
end
|
341
361
|
|
@@ -429,7 +449,7 @@ describe 'The method set_open_tracking' do
|
|
429
449
|
it 'warns of set_open_tracking deprecation' do
|
430
450
|
@mb_obj = Mailgun::MessageBuilder.new
|
431
451
|
expect(@mb_obj).to receive :warn
|
432
|
-
@mb_obj.set_open_tracking '
|
452
|
+
@mb_obj.set_open_tracking 'Yes'
|
433
453
|
end
|
434
454
|
end
|
435
455
|
|
@@ -440,19 +460,20 @@ describe 'The method track_opens' do
|
|
440
460
|
it 'enables/disables open tracking on a per message basis.' do
|
441
461
|
@mb_obj.track_opens('Yes')
|
442
462
|
|
443
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
463
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("yes")
|
464
|
+
expect(@mb_obj.message["o:tracking"]).to eq(["yes"])
|
444
465
|
|
445
466
|
@mb_obj.track_opens('No')
|
446
467
|
|
447
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
468
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("no")
|
448
469
|
|
449
470
|
@mb_obj.track_opens(true)
|
450
471
|
|
451
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
472
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("yes")
|
452
473
|
|
453
474
|
@mb_obj.track_opens(false)
|
454
475
|
|
455
|
-
expect(@mb_obj.message["o:tracking-opens"]
|
476
|
+
expect(@mb_obj.message["o:tracking-opens"]).to eq("no")
|
456
477
|
end
|
457
478
|
end
|
458
479
|
|
@@ -460,7 +481,7 @@ describe 'The method set_click_tracking' do
|
|
460
481
|
it 'warns of set_click_tracking deprecation' do
|
461
482
|
@mb_obj = Mailgun::MessageBuilder.new
|
462
483
|
expect(@mb_obj).to receive :warn
|
463
|
-
@mb_obj.set_click_tracking '
|
484
|
+
@mb_obj.set_click_tracking 'Yes'
|
464
485
|
end
|
465
486
|
end
|
466
487
|
|
@@ -471,23 +492,31 @@ describe 'The method track_clicks' do
|
|
471
492
|
it 'enables/disables click tracking on a per message basis.' do
|
472
493
|
@mb_obj.track_clicks('Yes')
|
473
494
|
|
474
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
495
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("yes")
|
496
|
+
expect(@mb_obj.message["o:tracking"]).to eq(["yes"])
|
475
497
|
|
476
498
|
@mb_obj.track_clicks('No')
|
477
499
|
|
478
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
500
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("no")
|
479
501
|
|
480
502
|
@mb_obj.track_clicks(true)
|
481
503
|
|
482
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
504
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("yes")
|
483
505
|
|
484
506
|
@mb_obj.track_clicks(false)
|
485
507
|
|
486
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
508
|
+
expect(@mb_obj.message["o:tracking-clicks"]).to eq("no")
|
487
509
|
|
488
510
|
@mb_obj.track_clicks('html')
|
489
511
|
|
490
|
-
expect(@mb_obj.message["o:tracking-clicks"]
|
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
|
491
520
|
end
|
492
521
|
end
|
493
522
|
|
@@ -547,9 +576,13 @@ describe 'The method variable' do
|
|
547
576
|
expect(@mb_obj.message["v:my-data"]).to be_kind_of(String)
|
548
577
|
expect(@mb_obj.message["v:my-data"].to_s).to eq('{"key":"value"}')
|
549
578
|
end
|
550
|
-
it '
|
551
|
-
data = '
|
552
|
-
|
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.')
|
553
586
|
end
|
554
587
|
end
|
555
588
|
|
@@ -597,3 +630,103 @@ describe 'The method message_id' do
|
|
597
630
|
expect(@mb_obj.message.has_key?('h:Message-Id')).to eq(false)
|
598
631
|
end
|
599
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
|