sendgrid-actionmailer 0.2.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +7 -5
- data/Appraisals +4 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -0
- data/README.md +178 -67
- data/lib/sendgrid_actionmailer/version.rb +1 -1
- data/lib/sendgrid_actionmailer.rb +189 -101
- data/sendgrid-actionmailer.gemspec +5 -4
- data/spec/lib/sendgrid_actionmailer_spec.rb +284 -268
- metadata +27 -29
- data/gemfiles/mail_2.5.gemfile.lock +0 -71
- data/gemfiles/mail_2.6.gemfile.lock +0 -66
@@ -4,25 +4,56 @@ require 'webmock/rspec'
|
|
4
4
|
module SendGridActionMailer
|
5
5
|
describe DeliveryMethod do
|
6
6
|
subject(:mailer) do
|
7
|
-
DeliveryMethod.new(
|
7
|
+
DeliveryMethod.new(api_key: 'key')
|
8
8
|
end
|
9
9
|
|
10
|
-
class TestClient
|
10
|
+
class TestClient
|
11
11
|
attr_reader :sent_mail
|
12
12
|
|
13
13
|
def send(mail)
|
14
14
|
@sent_mail = mail
|
15
15
|
super(mail)
|
16
16
|
end
|
17
|
+
|
18
|
+
def mail()
|
19
|
+
self
|
20
|
+
end
|
21
|
+
|
22
|
+
def _(param)
|
23
|
+
return self if param == 'send'
|
24
|
+
raise "Unknown param #{param.inspect}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(request_body:)
|
28
|
+
@sent_mail = request_body
|
29
|
+
OpenStruct.new(status_code: '200')
|
30
|
+
end
|
17
31
|
end
|
18
32
|
|
19
|
-
describe '
|
20
|
-
it '
|
21
|
-
|
33
|
+
describe 'settings' do
|
34
|
+
it 'has correct api_key' do
|
35
|
+
m = DeliveryMethod.new(api_key: 'ABCDEFG')
|
36
|
+
expect(m.settings[:api_key]).to eq('ABCDEFG')
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'default raise_delivery_errors' do
|
40
|
+
m = DeliveryMethod.new()
|
41
|
+
expect(m.settings[:raise_delivery_errors]).to eq(false)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'sets raise_delivery_errors' do
|
45
|
+
m = DeliveryMethod.new(raise_delivery_errors: true)
|
46
|
+
expect(m.settings[:raise_delivery_errors]).to eq(true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'default return_response' do
|
50
|
+
m = DeliveryMethod.new()
|
51
|
+
expect(mailer.settings[:return_response]).to eq(nil)
|
22
52
|
end
|
23
53
|
|
24
|
-
it '
|
25
|
-
|
54
|
+
it 'sets return_response' do
|
55
|
+
m = DeliveryMethod.new(return_response: true)
|
56
|
+
expect(m.settings[:return_response]).to eq(true)
|
26
57
|
end
|
27
58
|
end
|
28
59
|
|
@@ -32,7 +63,7 @@ module SendGridActionMailer
|
|
32
63
|
Mail.new(
|
33
64
|
to: 'test@sendgrid.com',
|
34
65
|
from: 'taco@cat.limo',
|
35
|
-
subject: 'Hello, world!'
|
66
|
+
subject: 'Hello, world!',
|
36
67
|
)
|
37
68
|
end
|
38
69
|
|
@@ -44,7 +75,36 @@ module SendGridActionMailer
|
|
44
75
|
|
45
76
|
it 'sets to' do
|
46
77
|
mailer.deliver!(mail)
|
47
|
-
expect(client.sent_mail
|
78
|
+
expect(client.sent_mail['personalizations'][0]).to include({"to"=>[{"email"=>"test@sendgrid.com"}]})
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'returns mailer itself' do
|
82
|
+
ret = mailer.deliver!(mail)
|
83
|
+
expect(ret).to eq(mailer)
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'returns api response' do
|
87
|
+
m = DeliveryMethod.new(return_response: true, api_key: 'key')
|
88
|
+
ret = m.deliver!(mail)
|
89
|
+
expect(ret.status_code).to eq('200')
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'to with a friendly name' do
|
93
|
+
before { mail.to = 'Test SendGrid <test@sendgrid.com>' }
|
94
|
+
|
95
|
+
it 'sets to' do
|
96
|
+
mailer.deliver!(mail)
|
97
|
+
expect(client.sent_mail['personalizations'][0]).to include({"to"=>[{"email"=>"test@sendgrid.com", "name"=>"Test SendGrid"}]})
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'to with a friendly name (with quotes)' do
|
102
|
+
before { mail.to = '"Test SendGrid" <test@sendgrid.com>' }
|
103
|
+
|
104
|
+
it 'sets to' do
|
105
|
+
mailer.deliver!(mail)
|
106
|
+
expect(client.sent_mail['personalizations'][0]).to include({"to"=>[{"email"=>"test@sendgrid.com", "name"=>"Test SendGrid"}]})
|
107
|
+
end
|
48
108
|
end
|
49
109
|
|
50
110
|
context 'there are ccs' do
|
@@ -52,7 +112,7 @@ module SendGridActionMailer
|
|
52
112
|
|
53
113
|
it 'sets cc' do
|
54
114
|
mailer.deliver!(mail)
|
55
|
-
expect(client.sent_mail
|
115
|
+
expect(client.sent_mail['personalizations'][0]).to include({"to"=>[{"email"=>"test@sendgrid.com"}], "cc"=>[{"email"=>"burrito@cat.limo"}]})
|
56
116
|
end
|
57
117
|
end
|
58
118
|
|
@@ -61,40 +121,44 @@ module SendGridActionMailer
|
|
61
121
|
|
62
122
|
it 'sets bcc' do
|
63
123
|
mailer.deliver!(mail)
|
64
|
-
expect(client.sent_mail
|
124
|
+
expect(client.sent_mail['personalizations'][0]).to include({"to"=>[{"email"=>"test@sendgrid.com"}], "bcc"=>[{"email"=>"nachos@cat.limo"}]})
|
65
125
|
end
|
66
126
|
end
|
67
127
|
|
68
|
-
context 'there
|
69
|
-
before { mail.
|
128
|
+
context 'there are bccs with a friendly name' do
|
129
|
+
before { mail.bcc = 'Taco Cat <nachos@cat.limo>' }
|
70
130
|
|
71
|
-
it 'sets
|
131
|
+
it 'sets bcc' do
|
72
132
|
mailer.deliver!(mail)
|
73
|
-
expect(client.sent_mail
|
133
|
+
expect(client.sent_mail['personalizations'][0]).to include({"to"=>[{"email"=>"test@sendgrid.com"}], "bcc"=>[{"email"=>"nachos@cat.limo", "name"=>"Taco Cat"}]})
|
74
134
|
end
|
75
135
|
end
|
76
136
|
|
77
|
-
context 'there
|
78
|
-
before { mail.
|
137
|
+
context 'there are bccs with a friendly name (with quotes)' do
|
138
|
+
before { mail.bcc = '"Taco Cat" <nachos@cat.limo>' }
|
79
139
|
|
80
|
-
it 'sets
|
140
|
+
it 'sets bcc' do
|
81
141
|
mailer.deliver!(mail)
|
82
|
-
expect(client.sent_mail
|
142
|
+
expect(client.sent_mail['personalizations'][0]).to include({"to"=>[{"email"=>"test@sendgrid.com"}], "bcc"=>[{"email"=>"nachos@cat.limo", "name"=>"Taco Cat"}]})
|
83
143
|
end
|
84
144
|
end
|
85
145
|
|
86
|
-
context 'there is a
|
87
|
-
before { mail.
|
146
|
+
context 'there is a reply to' do
|
147
|
+
before { mail.reply_to = 'nachos@cat.limo' }
|
88
148
|
|
89
|
-
it 'sets
|
149
|
+
it 'sets reply_to' do
|
90
150
|
mailer.deliver!(mail)
|
91
|
-
expect(client.sent_mail
|
151
|
+
expect(client.sent_mail['reply_to']).to eq({'email' => 'nachos@cat.limo'})
|
92
152
|
end
|
93
153
|
end
|
94
154
|
|
95
|
-
|
96
|
-
|
97
|
-
|
155
|
+
context 'there is a reply to with a friendly name' do
|
156
|
+
before { mail.reply_to = 'Taco Cat <nachos@cat.limo>' }
|
157
|
+
|
158
|
+
it 'sets reply_to' do
|
159
|
+
mailer.deliver!(mail)
|
160
|
+
expect(client.sent_mail['reply_to']).to eq('email' => 'nachos@cat.limo', 'name' => 'Taco Cat')
|
161
|
+
end
|
98
162
|
end
|
99
163
|
|
100
164
|
context 'from contains a friendly name' do
|
@@ -102,341 +166,293 @@ module SendGridActionMailer
|
|
102
166
|
|
103
167
|
it 'sets from' do
|
104
168
|
mailer.deliver!(mail)
|
105
|
-
expect(client.sent_mail
|
169
|
+
expect(client.sent_mail['from']).to eq('email' => 'taco@cat.limo', 'name' => 'Taco Cat')
|
106
170
|
end
|
171
|
+
end
|
172
|
+
|
173
|
+
context 'from contains a friendly name (with quotes)' do
|
174
|
+
before { mail.from = '"Taco Cat" <taco@cat.limo>'}
|
107
175
|
|
108
|
-
it 'sets
|
176
|
+
it 'sets from' do
|
109
177
|
mailer.deliver!(mail)
|
110
|
-
expect(client.sent_mail
|
178
|
+
expect(client.sent_mail['from']).to eq('email' => 'taco@cat.limo', 'name' => 'Taco Cat')
|
111
179
|
end
|
112
180
|
end
|
113
181
|
|
114
182
|
it 'sets subject' do
|
115
183
|
mailer.deliver!(mail)
|
116
|
-
expect(client.sent_mail
|
184
|
+
expect(client.sent_mail['subject']).to eq('Hello, world!')
|
117
185
|
end
|
118
186
|
|
119
187
|
it 'sets a text/plain body' do
|
120
188
|
mail.content_type = 'text/plain'
|
121
189
|
mail.body = 'I heard you like pineapple.'
|
122
190
|
mailer.deliver!(mail)
|
123
|
-
expect(client.sent_mail
|
191
|
+
expect(client.sent_mail['content']).to eq([
|
192
|
+
{
|
193
|
+
'type' => 'text/plain',
|
194
|
+
'value' => 'I heard you like pineapple.'
|
195
|
+
}
|
196
|
+
])
|
124
197
|
end
|
125
198
|
|
126
199
|
it 'sets a text/html body' do
|
127
200
|
mail.content_type = 'text/html'
|
128
201
|
mail.body = 'I heard you like <b>pineapple</b>.'
|
129
202
|
mailer.deliver!(mail)
|
130
|
-
expect(client.sent_mail.html).to eq('I heard you like <b>pineapple</b>.')
|
131
|
-
end
|
132
203
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
end
|
141
|
-
part.html_part = Mail::Part.new do
|
142
|
-
content_type 'text/html'
|
143
|
-
body 'I heard you like <b>pineapple</b>.'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
204
|
+
expect(client.sent_mail['content']).to eq([
|
205
|
+
{
|
206
|
+
'type' => 'text/html',
|
207
|
+
'value' => 'I heard you like <b>pineapple</b>.'
|
208
|
+
}
|
209
|
+
])
|
210
|
+
end
|
147
211
|
|
148
|
-
|
212
|
+
context 'send options' do
|
213
|
+
it 'sets a template_id' do
|
214
|
+
mail['template_id'] = '1'
|
149
215
|
mailer.deliver!(mail)
|
150
|
-
expect(client.sent_mail
|
216
|
+
expect(client.sent_mail['template_id']).to eq('1')
|
151
217
|
end
|
152
218
|
|
153
|
-
it 'sets
|
219
|
+
it 'sets sections' do
|
220
|
+
mail['sections'] = {'%foo%' => 'bar'}
|
154
221
|
mailer.deliver!(mail)
|
155
|
-
expect(client.sent_mail.
|
156
|
-
.to eq('I heard you like <b>pineapple</b>.')
|
222
|
+
expect(client.sent_mail['sections']).to eq({'%foo%' => 'bar'})
|
157
223
|
end
|
158
|
-
end
|
159
224
|
|
160
|
-
|
161
|
-
|
162
|
-
mail.content_type 'multipart/mixed'
|
163
|
-
mail.part do |part|
|
164
|
-
part.text_part = Mail::Part.new do
|
165
|
-
content_type 'text/plain'
|
166
|
-
body 'I heard you like pineapple.'
|
167
|
-
end
|
168
|
-
part.html_part = Mail::Part.new do
|
169
|
-
content_type 'text/html'
|
170
|
-
body 'I heard you like <b>pineapple</b>.'
|
171
|
-
end
|
172
|
-
end
|
173
|
-
mail.attachments['specs.rb'] = File.read(__FILE__)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'sets the text body' do
|
225
|
+
it 'sets headers' do
|
226
|
+
mail['headers'] = {'X-FOO' => 'bar'}
|
177
227
|
mailer.deliver!(mail)
|
178
|
-
expect(client.sent_mail
|
228
|
+
expect(client.sent_mail['headers']).to eq({'X-FOO' => 'bar'})
|
179
229
|
end
|
180
230
|
|
181
|
-
it 'sets
|
231
|
+
it 'sets categories' do
|
232
|
+
mail['categories'] = ['foo', 'bar']
|
182
233
|
mailer.deliver!(mail)
|
183
|
-
expect(client.sent_mail.
|
184
|
-
.to eq('I heard you like <b>pineapple</b>.')
|
234
|
+
expect(client.sent_mail['categories']).to eq(['foo', 'bar'])
|
185
235
|
end
|
186
236
|
|
187
|
-
it '
|
188
|
-
|
237
|
+
it 'sets custom_args' do
|
238
|
+
mail['custom_args'] = {'campaign' => 'welcome'}
|
189
239
|
mailer.deliver!(mail)
|
190
|
-
|
191
|
-
expect(attachment[:name]).to eq('specs.rb')
|
192
|
-
expect(attachment[:file].content_type.to_s).to eq('application/x-ruby')
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
context 'multipart/related' do
|
197
|
-
before do
|
198
|
-
mail.content_type 'multipart/related'
|
199
|
-
mail.part do |part|
|
200
|
-
part.text_part = Mail::Part.new do
|
201
|
-
content_type 'text/plain'
|
202
|
-
body 'I heard you like pineapple.'
|
203
|
-
end
|
204
|
-
part.html_part = Mail::Part.new do
|
205
|
-
content_type 'text/html'
|
206
|
-
body 'I heard you like <b>pineapple</b>.'
|
207
|
-
end
|
208
|
-
end
|
209
|
-
mail.attachments.inline['specs.rb'] = File.read(__FILE__)
|
240
|
+
expect(client.sent_mail['custom_args']).to eq({'campaign' => 'welcome'})
|
210
241
|
end
|
211
242
|
|
212
|
-
it 'sets
|
243
|
+
it 'sets send_at and batch_id' do
|
244
|
+
epoch = Time.now.to_i
|
245
|
+
mail['send_at'] = epoch
|
246
|
+
mail['batch_id'] = 3
|
213
247
|
mailer.deliver!(mail)
|
214
|
-
expect(client.sent_mail
|
248
|
+
expect(client.sent_mail['send_at']).to eq(epoch)
|
249
|
+
expect(client.sent_mail['batch_id']).to eq('3')
|
215
250
|
end
|
216
251
|
|
217
|
-
it 'sets
|
252
|
+
it 'sets asm' do
|
253
|
+
asm = {'group_id' => 99, 'groups_to_display' => [4,5,6,7,8]}
|
254
|
+
mail['asm'] = asm
|
218
255
|
mailer.deliver!(mail)
|
219
|
-
expect(client.sent_mail.
|
220
|
-
.to eq('I heard you like <b>pineapple</b>.')
|
256
|
+
expect(client.sent_mail['asm']).to eq(asm)
|
221
257
|
end
|
222
258
|
|
223
|
-
it '
|
224
|
-
|
259
|
+
it 'sets ip_pool_name' do
|
260
|
+
mail['ip_pool_name'] = 'marketing'
|
225
261
|
mailer.deliver!(mail)
|
226
|
-
|
227
|
-
expect(content[:name]).to eq('specs.rb')
|
228
|
-
expect(content[:file].content_type.to_s).to eq('application/x-ruby')
|
229
|
-
expect(content[:cid].class).to eq(String)
|
262
|
+
expect(client.sent_mail['ip_pool_name']).to eq('marketing')
|
230
263
|
end
|
231
|
-
end
|
232
|
-
|
233
|
-
context 'SMTPAPI' do
|
234
|
-
context 'it is not JSON' do
|
235
|
-
before { mail['X-SMTPAPI'] = '<xml>JSON sucks!</xml>' }
|
236
264
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
context 'filters are present' do
|
246
|
-
before do
|
247
|
-
mail['X-SMTPAPI'] = {
|
248
|
-
filters: {
|
249
|
-
clicktrack: {
|
250
|
-
settings: {
|
251
|
-
enable: 0
|
252
|
-
}
|
253
|
-
},
|
254
|
-
dkim: {
|
255
|
-
settings: {
|
256
|
-
domain: 'example.com',
|
257
|
-
use_from: false
|
258
|
-
}
|
259
|
-
}
|
260
|
-
}
|
261
|
-
}.to_json
|
262
|
-
end
|
263
|
-
|
264
|
-
it 'gets attached' do
|
265
|
+
context 'parse object' do
|
266
|
+
it "should parse 1.8 hash" do
|
267
|
+
asm = {'group_id' => 99, 'groups_to_display' => [4,5,6,7,8]}
|
268
|
+
mail['asm'] = asm
|
265
269
|
mailer.deliver!(mail)
|
266
|
-
expect(client.sent_mail
|
267
|
-
'clicktrack' => {
|
268
|
-
'settings' => {
|
269
|
-
'enable' => 0
|
270
|
-
}
|
271
|
-
},
|
272
|
-
'dkim' => {
|
273
|
-
'settings' => {
|
274
|
-
'domain' => 'example.com',
|
275
|
-
'use_from' => false
|
276
|
-
}
|
277
|
-
}
|
278
|
-
})
|
270
|
+
expect(client.sent_mail['asm']).to eq({"group_id" => 99, "groups_to_display" => [4,5,6,7,8]})
|
279
271
|
end
|
280
|
-
end
|
281
272
|
|
282
|
-
|
283
|
-
|
284
|
-
mail['
|
273
|
+
it "should parse 1.9 hash" do
|
274
|
+
asm = { group_id: 99, groups_to_display: [4,5,6,7,8]}
|
275
|
+
mail['asm'] = asm
|
276
|
+
mailer.deliver!(mail)
|
277
|
+
expect(client.sent_mail['asm']).to eq({"group_id" => 99, "groups_to_display" => [4,5,6,7,8]})
|
285
278
|
end
|
286
279
|
|
287
|
-
it
|
280
|
+
it "should parse json" do
|
281
|
+
asm = {'group_id' => 99, 'groups_to_display' => [4,5,6,7,8]}
|
282
|
+
mail['asm'] = asm.to_json
|
288
283
|
mailer.deliver!(mail)
|
289
|
-
expect(client.sent_mail
|
284
|
+
expect(client.sent_mail['asm']).to eq({"group_id" => 99, "groups_to_display" => [4,5,6,7,8]})
|
290
285
|
end
|
291
286
|
end
|
292
287
|
|
293
|
-
context '
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
}.to_json
|
298
|
-
end
|
299
|
-
|
300
|
-
it 'attaches them all' do
|
288
|
+
context 'mail_settings' do
|
289
|
+
it 'sets bcc' do
|
290
|
+
bcc = { 'bcc' => { 'enable' => true, 'email' => 'test@example.com' }}
|
291
|
+
mail['mail_settings'] = bcc
|
301
292
|
mailer.deliver!(mail)
|
302
|
-
expect(client.sent_mail
|
303
|
-
'food_feline',
|
304
|
-
'cuisine_canine',
|
305
|
-
])
|
293
|
+
expect(client.sent_mail['mail_settings']).to eq(bcc)
|
306
294
|
end
|
307
|
-
end
|
308
295
|
|
309
|
-
|
310
|
-
|
311
|
-
mail['
|
312
|
-
|
313
|
-
|
296
|
+
it 'sets bypass_list_management' do
|
297
|
+
bypass = { 'bypass_list_management' => { 'enable' => true }}
|
298
|
+
mail['mail_settings'] = bypass
|
299
|
+
mailer.deliver!(mail)
|
300
|
+
expect(client.sent_mail['mail_settings']).to eq(bypass)
|
314
301
|
end
|
315
302
|
|
316
|
-
it '
|
303
|
+
it 'sets footer' do
|
304
|
+
footer = {'footer' => { 'enable' => true, 'text' => 'Footer Text', 'html' => '<html><body>Footer Text</body></html>'}}
|
305
|
+
mail['mail_settings'] = footer
|
317
306
|
mailer.deliver!(mail)
|
318
|
-
expect(client.sent_mail
|
307
|
+
expect(client.sent_mail['mail_settings']).to eq(footer)
|
319
308
|
end
|
320
|
-
end
|
321
309
|
|
322
|
-
|
323
|
-
|
324
|
-
mail['
|
325
|
-
|
326
|
-
|
310
|
+
it 'sets sandbox_mode' do
|
311
|
+
sandbox = {'sandbox_mode' => { 'enable' => true }}
|
312
|
+
mail['mail_settings'] = sandbox
|
313
|
+
mailer.deliver!(mail)
|
314
|
+
expect(client.sent_mail['mail_settings']).to eq(sandbox)
|
327
315
|
end
|
328
316
|
|
329
|
-
it '
|
317
|
+
it 'sets spam_check' do
|
318
|
+
spam_check = {'spam_check' => { 'enable' => true, 'threshold' => 1, 'post_to_url' => 'https://spamcatcher.sendgrid.com'}}
|
319
|
+
mail['mail_settings'] = spam_check
|
330
320
|
mailer.deliver!(mail)
|
331
|
-
expect(client.sent_mail
|
321
|
+
expect(client.sent_mail['mail_settings']).to eq(spam_check)
|
332
322
|
end
|
333
323
|
end
|
334
324
|
|
335
|
-
context '
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
}
|
342
|
-
}.to_json
|
325
|
+
context 'tracking_settings' do
|
326
|
+
it 'sets click_tracking' do
|
327
|
+
tracking = { 'click_tracking' => { 'enable' => false, 'enable_text' => false }}
|
328
|
+
mail['tracking_settings'] = tracking
|
329
|
+
mailer.deliver!(mail)
|
330
|
+
expect(client.sent_mail['tracking_settings']).to eq(tracking)
|
343
331
|
end
|
344
332
|
|
345
|
-
it '
|
333
|
+
it 'sets open_tracking' do
|
334
|
+
tracking = { 'open_tracking' => { 'enable' => true, 'substitution_tag' => 'Optional tag to replace with the open image in the body of the message' }}
|
335
|
+
mail['tracking_settings'] = tracking
|
346
336
|
mailer.deliver!(mail)
|
347
|
-
expect(client.sent_mail
|
348
|
-
":sectionName1" => "section 1 text",
|
349
|
-
":sectionName2" => "section 2 text"
|
350
|
-
})
|
337
|
+
expect(client.sent_mail['tracking_settings']).to eq(tracking)
|
351
338
|
end
|
352
|
-
end
|
353
339
|
|
354
|
-
|
355
|
-
|
356
|
-
mail['
|
357
|
-
|
358
|
-
|
359
|
-
"John",
|
360
|
-
"Jane"
|
361
|
-
],
|
362
|
-
"-customerID-" => [
|
363
|
-
"1234",
|
364
|
-
"5678"
|
365
|
-
],
|
366
|
-
}
|
367
|
-
}.to_json
|
340
|
+
it 'sets subscription_tracking' do
|
341
|
+
tracking = { 'subscription_tracking' => { 'enable' => true, 'text' => 'text to insert into the text/plain portion of the message', 'html' => 'html to insert into the text/html portion of the message', 'substitution_tag' => 'Optional tag to replace with the open image in the body of the def message' }}
|
342
|
+
mail['tracking_settings'] = tracking
|
343
|
+
mailer.deliver!(mail)
|
344
|
+
expect(client.sent_mail['tracking_settings']).to eq(tracking)
|
368
345
|
end
|
369
346
|
|
370
|
-
it '
|
347
|
+
it 'sets ganalytics' do
|
348
|
+
tracking = { 'ganalytics' => {'enable' => true, 'utm_source' => 'some source', 'utm_medium' => 'some medium', 'utm_term' => 'some term', 'utm_content' => 'some content', 'utm_campaign' => 'some campaign' }}
|
349
|
+
mail['tracking_settings'] = tracking
|
371
350
|
mailer.deliver!(mail)
|
372
|
-
expect(client.sent_mail
|
373
|
-
"-name-" => [
|
374
|
-
"John",
|
375
|
-
"Jane"
|
376
|
-
],
|
377
|
-
"-customerID-" => [
|
378
|
-
"1234",
|
379
|
-
"5678"
|
380
|
-
],
|
381
|
-
})
|
351
|
+
expect(client.sent_mail['tracking_settings']).to eq(tracking)
|
382
352
|
end
|
383
353
|
end
|
354
|
+
end
|
384
355
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
356
|
+
context 'multipart/alternative' do
|
357
|
+
before do
|
358
|
+
mail.content_type 'multipart/alternative'
|
359
|
+
mail.part do |part|
|
360
|
+
part.text_part = Mail::Part.new do
|
361
|
+
content_type 'text/plain'
|
362
|
+
body 'I heard you like pineapple.'
|
363
|
+
end
|
364
|
+
part.html_part = Mail::Part.new do
|
365
|
+
content_type 'text/html'
|
366
|
+
body 'I heard you like <b>pineapple</b>.'
|
367
|
+
end
|
390
368
|
end
|
369
|
+
end
|
391
370
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
371
|
+
it 'sets the text and html body' do
|
372
|
+
mailer.deliver!(mail)
|
373
|
+
expect(client.sent_mail['content']).to include({
|
374
|
+
'type' => 'text/html',
|
375
|
+
'value' => 'I heard you like <b>pineapple</b>.'
|
376
|
+
})
|
377
|
+
expect(client.sent_mail['content']).to include({
|
378
|
+
'type' => 'text/plain',
|
379
|
+
'value' => 'I heard you like pineapple.'
|
380
|
+
})
|
396
381
|
end
|
382
|
+
end
|
397
383
|
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
384
|
+
context 'multipart/mixed' do
|
385
|
+
before do
|
386
|
+
mail.content_type 'multipart/mixed'
|
387
|
+
mail.part do |part|
|
388
|
+
part.text_part = Mail::Part.new do
|
389
|
+
content_type 'text/plain'
|
390
|
+
body 'I heard you like pineapple.'
|
391
|
+
end
|
392
|
+
part.html_part = Mail::Part.new do
|
393
|
+
content_type 'text/html'
|
394
|
+
body 'I heard you like <b>pineapple</b>.'
|
395
|
+
end
|
406
396
|
end
|
397
|
+
mail.attachments['specs.rb'] = File.read(__FILE__)
|
398
|
+
end
|
407
399
|
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
400
|
+
it 'sets the text and html body' do
|
401
|
+
mailer.deliver!(mail)
|
402
|
+
expect(client.sent_mail['content']).to include({
|
403
|
+
'type' => 'text/html',
|
404
|
+
'value' => 'I heard you like <b>pineapple</b>.'
|
405
|
+
})
|
406
|
+
expect(client.sent_mail['content']).to include({
|
407
|
+
'type' => 'text/plain',
|
408
|
+
'value' => 'I heard you like pineapple.'
|
409
|
+
})
|
415
410
|
end
|
416
411
|
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
412
|
+
it 'adds the attachment' do
|
413
|
+
expect(mail.attachments.first.read).to eq(File.read(__FILE__))
|
414
|
+
mailer.deliver!(mail)
|
415
|
+
attachment = client.sent_mail['attachments'].first
|
416
|
+
expect(attachment['filename']).to eq('specs.rb')
|
417
|
+
expect(attachment['type']).to eq('application/x-ruby')
|
418
|
+
end
|
419
|
+
end
|
423
420
|
|
424
|
-
|
425
|
-
|
426
|
-
|
421
|
+
context 'multipart/related' do
|
422
|
+
before do
|
423
|
+
mail.content_type 'multipart/related'
|
424
|
+
mail.part do |part|
|
425
|
+
part.text_part = Mail::Part.new do
|
426
|
+
content_type 'text/plain'
|
427
|
+
body 'I heard you like pineapple.'
|
428
|
+
end
|
429
|
+
part.html_part = Mail::Part.new do
|
430
|
+
content_type 'text/html'
|
431
|
+
body 'I heard you like <b>pineapple</b>.'
|
432
|
+
end
|
427
433
|
end
|
434
|
+
mail.attachments.inline['specs.rb'] = File.read(__FILE__)
|
428
435
|
end
|
429
436
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
437
|
+
it 'sets the text and html body' do
|
438
|
+
mailer.deliver!(mail)
|
439
|
+
expect(client.sent_mail['content']).to include({
|
440
|
+
'type' => 'text/html',
|
441
|
+
'value' => 'I heard you like <b>pineapple</b>.'
|
442
|
+
})
|
443
|
+
expect(client.sent_mail['content']).to include({
|
444
|
+
'type' => 'text/plain',
|
445
|
+
'value' => 'I heard you like pineapple.'
|
446
|
+
})
|
447
|
+
end
|
435
448
|
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
449
|
+
it 'adds the inline attachment' do
|
450
|
+
expect(mail.attachments.first.read).to eq(File.read(__FILE__))
|
451
|
+
mailer.deliver!(mail)
|
452
|
+
content = client.sent_mail['attachments'].first
|
453
|
+
expect(content['filename']).to eq('specs.rb')
|
454
|
+
expect(content['type']).to eq('application/x-ruby')
|
455
|
+
expect(content['content_id'].class).to eq(String)
|
440
456
|
end
|
441
457
|
end
|
442
458
|
end
|