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