mandrill_mailer 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +3 -0
- data/README.md +37 -0
- data/lib/mandrill_mailer.rb +1 -0
- data/lib/mandrill_mailer/core_mailer.rb +367 -0
- data/lib/mandrill_mailer/message_mailer.rb +212 -0
- data/lib/mandrill_mailer/template_mailer.rb +10 -233
- data/lib/mandrill_mailer/version.rb +1 -1
- data/spec/message_mailer_spec.rb +148 -0
- data/spec/template_mailer_spec.rb +65 -27
- metadata +6 -2
@@ -0,0 +1,148 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
describe MandrillMailer::MessageMailer do
|
5
|
+
let(:image_path) { '/assets/image.jpg' }
|
6
|
+
let(:default_host) { 'localhost:3000' }
|
7
|
+
let(:mailer) { described_class.new }
|
8
|
+
let(:api_key) { '1237861278' }
|
9
|
+
|
10
|
+
|
11
|
+
let(:from_email) { 'from@email.com' }
|
12
|
+
let(:from_name) { 'Example Name' }
|
13
|
+
let(:var_name) { 'USER_NAME' }
|
14
|
+
let(:var_content) { 'bobert' }
|
15
|
+
let(:var_rcpt_name) { 'USER_INFO' }
|
16
|
+
let(:var_rcpt_content) { 'boboblacksheep' }
|
17
|
+
let(:to_email) { 'bob@email.com' }
|
18
|
+
let(:to_name) { 'bob' }
|
19
|
+
let(:attachment_file) { File.read(File.expand_path('spec/support/test_image.png')) }
|
20
|
+
let(:attachment_filename) { 'test_image.png' }
|
21
|
+
let(:attachment_mimetype) { 'image/png' }
|
22
|
+
|
23
|
+
let(:image_file) { File.read(File.expand_path('spec/support/test_image.png')) }
|
24
|
+
let(:image_filename) { 'test_image.png' }
|
25
|
+
let(:image_mimetype) { 'image/png' }
|
26
|
+
|
27
|
+
let(:send_at) { Time.utc(2020, 1, 1, 8, 0) }
|
28
|
+
let(:bcc) { "bcc@email.com" }
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
let(:message_args) do
|
33
|
+
{
|
34
|
+
text: "Example text content",
|
35
|
+
html: "<p>Example HTML content</p>",
|
36
|
+
view_content_link: "http://www.nba.com",
|
37
|
+
from: from_email,
|
38
|
+
subject: "super secret",
|
39
|
+
to: {'email' => to_email, 'name' => to_name},
|
40
|
+
preserve_recipients: false,
|
41
|
+
vars: {
|
42
|
+
var_name => var_content
|
43
|
+
},
|
44
|
+
recipient_vars: [
|
45
|
+
{ to_email => { var_rcpt_name => var_rcpt_content } }
|
46
|
+
],
|
47
|
+
headers: {"Reply-To" => "support@email.com"},
|
48
|
+
bcc: bcc,
|
49
|
+
tags: ['tag1'],
|
50
|
+
subaccount: "subaccount1",
|
51
|
+
google_analytics_domains: ["http://site.com"],
|
52
|
+
google_analytics_campaign: '1237423474',
|
53
|
+
attachments: [{file: attachment_file, filename: attachment_filename, mimetype: attachment_mimetype}],
|
54
|
+
images: [{file: image_file, filename: image_filename, mimetype: image_mimetype}],
|
55
|
+
inline_css: true,
|
56
|
+
important: true,
|
57
|
+
send_at: send_at,
|
58
|
+
track_opens: false,
|
59
|
+
track_clicks: false,
|
60
|
+
url_strip_qs: false
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
before do
|
65
|
+
MandrillMailer.config.api_key = api_key
|
66
|
+
MandrillMailer.config.default_url_options = { host: default_host }
|
67
|
+
#MandrillMailer.config.stub(:image_path).and_return(image_path)
|
68
|
+
allow(MandrillMailer.config).to receive(:image_path).and_return(image_path)
|
69
|
+
|
70
|
+
MandrillMailer::MessageMailer.default from: from_email, from_name: from_name
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
describe '#mandrill_message_mail' do
|
75
|
+
subject { mailer.mandrill_mail(message_args) }
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
it 'should not set the html' do
|
80
|
+
expect(subject.html).to be_nil
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'should not set the text' do
|
84
|
+
expect(subject.text).to be_nil
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
it 'should set send_at option' do
|
89
|
+
expect(subject.send_at).to eq('2020-01-01 08:00:00')
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
context "with interceptor" do
|
95
|
+
before(:each) do
|
96
|
+
@intercepted_params = {
|
97
|
+
to: { email: 'interceptedto@test.com', name: 'Mr. Interceptor' },
|
98
|
+
tags: ['intercepted-tag'],
|
99
|
+
bcc_address: 'interceptedbbc@email.com'
|
100
|
+
}
|
101
|
+
MandrillMailer.config.interceptor_params = @intercepted_params
|
102
|
+
end
|
103
|
+
|
104
|
+
after do
|
105
|
+
MandrillMailer.config.interceptor_params = nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise an error if interceptor params is not a Hash" do
|
109
|
+
MandrillMailer.config.interceptor_params = "error"
|
110
|
+
expect { subject }.to raise_error(MandrillMailer::MessageMailer::InvalidInterceptorParams, "The interceptor_params config must be a Hash")
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should produce the correct message' do
|
114
|
+
expect(subject.message.to_a - {
|
115
|
+
"text" => "Example text content",
|
116
|
+
"html" => "<p>Example HTML content</p>",
|
117
|
+
"view_content_link" => "http://www.nba.com",
|
118
|
+
"subject" => message_args[:subject],
|
119
|
+
"from_email" => from_email,
|
120
|
+
"from_name" => from_name,
|
121
|
+
"to" => @intercepted_params[:to],
|
122
|
+
"headers" => message_args[:headers],
|
123
|
+
"important" => message_args[:important],
|
124
|
+
"inline_css" => message_args[:inline_css],
|
125
|
+
"track_opens" => message_args[:track_opens],
|
126
|
+
"track_clicks" => message_args[:track_clicks],
|
127
|
+
"auto_text" => true,
|
128
|
+
"url_strip_qs" => message_args[:url_strip_qs],
|
129
|
+
"preserve_recipients" => false,
|
130
|
+
"bcc_address" => @intercepted_params[:bcc_address],
|
131
|
+
"global_merge_vars" => [{"name" => var_name, "content" => var_content}],
|
132
|
+
"merge_vars" => [{"rcpt" => to_email, "vars" => [{"name" => var_rcpt_name, "content" => var_rcpt_content}]}],
|
133
|
+
"tags" => @intercepted_params[:tags],
|
134
|
+
"metadata" => message_args[:metadata],
|
135
|
+
"subaccount" => message_args[:subaccount],
|
136
|
+
"google_analytics_domains" => message_args[:google_analytics_domains],
|
137
|
+
"google_analytics_campaign" => message_args[:google_analytics_campaign],
|
138
|
+
"attachments" => [{'type' => attachment_mimetype, 'name' => attachment_filename, 'content' => Base64.encode64(attachment_file)}],
|
139
|
+
"images" => [{'type' => image_mimetype, 'name' => image_filename, 'content' => Base64.encode64(image_file)}]
|
140
|
+
}.to_a).to eq []
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
end
|
@@ -58,11 +58,46 @@ describe MandrillMailer::TemplateMailer do
|
|
58
58
|
url_strip_qs: false
|
59
59
|
}
|
60
60
|
end
|
61
|
+
|
62
|
+
|
63
|
+
let(:message_args) do
|
64
|
+
{
|
65
|
+
text: "Example text content",
|
66
|
+
html: "<p>Example HTML content</p>",
|
67
|
+
view_content_link: "http://www.nba.com",
|
68
|
+
from: from_email,
|
69
|
+
subject: "super secret",
|
70
|
+
to: {'email' => to_email, 'name' => to_name},
|
71
|
+
preserve_recipients: false,
|
72
|
+
vars: {
|
73
|
+
var_name => var_content
|
74
|
+
},
|
75
|
+
recipient_vars: [
|
76
|
+
{ to_email => { var_rcpt_name => var_rcpt_content } }
|
77
|
+
],
|
78
|
+
headers: {"Reply-To" => "support@email.com"},
|
79
|
+
bcc: bcc,
|
80
|
+
tags: ['tag1'],
|
81
|
+
subaccount: "subaccount1",
|
82
|
+
google_analytics_domains: ["http://site.com"],
|
83
|
+
google_analytics_campaign: '1237423474',
|
84
|
+
attachments: [{file: attachment_file, filename: attachment_filename, mimetype: attachment_mimetype}],
|
85
|
+
images: [{file: image_file, filename: image_filename, mimetype: image_mimetype}],
|
86
|
+
inline_css: true,
|
87
|
+
important: true,
|
88
|
+
send_at: send_at,
|
89
|
+
track_opens: false,
|
90
|
+
track_clicks: false,
|
91
|
+
url_strip_qs: false
|
92
|
+
}
|
93
|
+
end
|
61
94
|
|
62
95
|
before do
|
63
96
|
MandrillMailer.config.api_key = api_key
|
64
97
|
MandrillMailer.config.default_url_options = { host: default_host }
|
65
|
-
MandrillMailer.config.stub(:image_path).and_return(image_path)
|
98
|
+
#MandrillMailer.config.stub(:image_path).and_return(image_path)
|
99
|
+
allow(MandrillMailer.config).to receive(:image_path).and_return(image_path)
|
100
|
+
|
66
101
|
MandrillMailer::TemplateMailer.default from: from_email, from_name: from_name
|
67
102
|
end
|
68
103
|
|
@@ -87,13 +122,14 @@ describe MandrillMailer::TemplateMailer do
|
|
87
122
|
end
|
88
123
|
|
89
124
|
it 'should return the image url' do
|
90
|
-
mailer.send(:image_path, image).should eq ActionController::Base.asset_path(image)
|
125
|
+
#mailer.send(:image_path, image).should eq ActionController::Base.asset_path(image)
|
126
|
+
expect(mailer.send(:image_path, image)).to eq(ActionController::Base.asset_path(image))
|
91
127
|
end
|
92
128
|
end
|
93
129
|
|
94
130
|
context 'Rails does not exist' do
|
95
131
|
it 'should raise exception' do
|
96
|
-
|
132
|
+
expect{ subject }.to raise_error
|
97
133
|
end
|
98
134
|
end
|
99
135
|
end
|
@@ -123,11 +159,11 @@ describe MandrillMailer::TemplateMailer do
|
|
123
159
|
|
124
160
|
describe '#format_boolean' do
|
125
161
|
it 'only returns true or false' do
|
126
|
-
mailer.send(:format_boolean, 1).
|
127
|
-
mailer.send(:format_boolean, '1').
|
128
|
-
mailer.send(:format_boolean, nil).
|
129
|
-
mailer.send(:format_boolean, false).
|
130
|
-
mailer.send(:format_boolean, true).
|
162
|
+
expect(mailer.send(:format_boolean, 1)).to eq true
|
163
|
+
expect(mailer.send(:format_boolean, '1')).to eq true
|
164
|
+
expect(mailer.send(:format_boolean, nil)).to eq false
|
165
|
+
expect(mailer.send(:format_boolean, false)).to eq false
|
166
|
+
expect(mailer.send(:format_boolean, true)).to eq true
|
131
167
|
end
|
132
168
|
end
|
133
169
|
|
@@ -176,15 +212,16 @@ describe MandrillMailer::TemplateMailer do
|
|
176
212
|
end
|
177
213
|
|
178
214
|
it 'should set the template name' do
|
179
|
-
subject.template_name.
|
215
|
+
expect(subject.template_name).to eq 'Email Template'
|
180
216
|
end
|
181
217
|
|
218
|
+
|
182
219
|
it 'should set the template content' do
|
183
|
-
subject.template_content.
|
220
|
+
expect(subject.template_content).to eq [{'name' => template_content_name, 'content' => template_content_content}]
|
184
221
|
end
|
185
222
|
|
186
223
|
it 'should retain data method' do
|
187
|
-
subject.data.
|
224
|
+
expect(subject.data).to eq({
|
188
225
|
"key" => MandrillMailer.config.api_key,
|
189
226
|
"template_name" => subject.template_name,
|
190
227
|
"template_content" => subject.template_content,
|
@@ -196,12 +233,12 @@ describe MandrillMailer::TemplateMailer do
|
|
196
233
|
end
|
197
234
|
|
198
235
|
it 'should set send_at option' do
|
199
|
-
subject.send_at.
|
236
|
+
expect(subject.send_at).to eq('2020-01-01 08:00:00')
|
200
237
|
end
|
201
238
|
|
202
239
|
context "without interceptor" do
|
203
240
|
it 'should produce the correct message' do
|
204
|
-
subject.message.
|
241
|
+
expect(subject.message).to eq ({
|
205
242
|
"subject" => args[:subject],
|
206
243
|
"from_email" => from_email,
|
207
244
|
"from_name" => from_name,
|
@@ -248,7 +285,7 @@ describe MandrillMailer::TemplateMailer do
|
|
248
285
|
end
|
249
286
|
|
250
287
|
it 'should produce the correct message' do
|
251
|
-
subject.message.
|
288
|
+
expect(subject.message).to eq ({
|
252
289
|
"subject" => args[:subject],
|
253
290
|
"from_email" => from_email,
|
254
291
|
"from_name" => from_name,
|
@@ -276,6 +313,7 @@ describe MandrillMailer::TemplateMailer do
|
|
276
313
|
end
|
277
314
|
end
|
278
315
|
|
316
|
+
|
279
317
|
describe 'url helpers in mailer' do
|
280
318
|
subject { mailer.send(:course_url) }
|
281
319
|
|
@@ -300,19 +338,19 @@ describe MandrillMailer::TemplateMailer do
|
|
300
338
|
end
|
301
339
|
|
302
340
|
it 'should return the correct route' do
|
303
|
-
subject.
|
341
|
+
expect(subject).to eq router.course_url(host: host)
|
304
342
|
end
|
305
343
|
|
306
344
|
context 'route helper with an argument' do
|
307
345
|
it 'should return the correct route' do
|
308
|
-
subject.
|
346
|
+
expect(subject).to eq router.course_url({id: 1, title: 'zombies'}, host: host)
|
309
347
|
end
|
310
348
|
end
|
311
349
|
end
|
312
350
|
|
313
351
|
context 'Rails is not defined' do
|
314
352
|
it 'should raise an exception' do
|
315
|
-
|
353
|
+
expect{subject}.to raise_error
|
316
354
|
end
|
317
355
|
end
|
318
356
|
end
|
@@ -326,8 +364,8 @@ describe MandrillMailer::TemplateMailer do
|
|
326
364
|
default from_name: 'ClassB'
|
327
365
|
end
|
328
366
|
|
329
|
-
klassA.mandrill_mail({vars: {}}).message['from_name'].
|
330
|
-
klassB.mandrill_mail({vars: {}}).message['from_name'].
|
367
|
+
expect(klassA.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassA'
|
368
|
+
expect(klassB.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassB'
|
331
369
|
end
|
332
370
|
|
333
371
|
it 'should use defaults from the parent class' do
|
@@ -337,7 +375,7 @@ describe MandrillMailer::TemplateMailer do
|
|
337
375
|
klassB = Class.new(klassA) do
|
338
376
|
end
|
339
377
|
|
340
|
-
klassB.mandrill_mail({vars:{}}).message['from_name'].
|
378
|
+
expect(klassB.mandrill_mail({vars:{}}).message['from_name']).to eq 'ClassA'
|
341
379
|
end
|
342
380
|
|
343
381
|
it 'should allow overriding defaults from the parent' do
|
@@ -348,7 +386,7 @@ describe MandrillMailer::TemplateMailer do
|
|
348
386
|
default from_name: 'ClassB'
|
349
387
|
end
|
350
388
|
|
351
|
-
klassB.mandrill_mail({vars:{}}).message['from_name'].
|
389
|
+
expect(klassB.mandrill_mail({vars:{}}).message['from_name']).to eq 'ClassB'
|
352
390
|
end
|
353
391
|
end
|
354
392
|
|
@@ -360,7 +398,7 @@ describe MandrillMailer::TemplateMailer do
|
|
360
398
|
end
|
361
399
|
end
|
362
400
|
|
363
|
-
klassA.respond_to
|
401
|
+
expect(klassA).to respond_to('test_method')
|
364
402
|
end
|
365
403
|
it 'can respond to a string' do
|
366
404
|
klassA = Class.new(MandrillMailer::TemplateMailer) do
|
@@ -369,7 +407,7 @@ describe MandrillMailer::TemplateMailer do
|
|
369
407
|
end
|
370
408
|
end
|
371
409
|
|
372
|
-
klassA.respond_to
|
410
|
+
expect(klassA).to respond_to('test_method')
|
373
411
|
end
|
374
412
|
end
|
375
413
|
|
@@ -377,7 +415,7 @@ describe MandrillMailer::TemplateMailer do
|
|
377
415
|
subject { mailer.mandrill_mail(args) }
|
378
416
|
|
379
417
|
it "returns the from email" do
|
380
|
-
subject.from.
|
418
|
+
expect(subject.from).to eq from_email
|
381
419
|
end
|
382
420
|
end
|
383
421
|
|
@@ -385,7 +423,7 @@ describe MandrillMailer::TemplateMailer do
|
|
385
423
|
subject { mailer.mandrill_mail(args) }
|
386
424
|
|
387
425
|
it "returns the to email data" do
|
388
|
-
subject.to.
|
426
|
+
expect(subject.to).to eq [{"email" => to_email, "name" => to_name}]
|
389
427
|
end
|
390
428
|
end
|
391
429
|
|
@@ -394,7 +432,7 @@ describe MandrillMailer::TemplateMailer do
|
|
394
432
|
|
395
433
|
it "updates the to email data" do
|
396
434
|
subject.to = 'bob@example.com'
|
397
|
-
subject.to.
|
435
|
+
expect(subject.to).to eq [{"email" => "bob@example.com", "name" => "bob@example.com"}]
|
398
436
|
end
|
399
437
|
end
|
400
438
|
|
@@ -402,7 +440,7 @@ describe MandrillMailer::TemplateMailer do
|
|
402
440
|
subject { mailer.mandrill_mail(args) }
|
403
441
|
|
404
442
|
it "returns the bcc email/s" do
|
405
|
-
subject.bcc.
|
443
|
+
expect(subject.bcc).to eq bcc
|
406
444
|
end
|
407
445
|
end
|
408
446
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mandrill_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Rensel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -93,6 +93,8 @@ files:
|
|
93
93
|
- Gemfile
|
94
94
|
- README.md
|
95
95
|
- lib/mandrill_mailer.rb
|
96
|
+
- lib/mandrill_mailer/core_mailer.rb
|
97
|
+
- lib/mandrill_mailer/message_mailer.rb
|
96
98
|
- lib/mandrill_mailer/mock.rb
|
97
99
|
- lib/mandrill_mailer/offline.rb
|
98
100
|
- lib/mandrill_mailer/railtie.rb
|
@@ -100,6 +102,7 @@ files:
|
|
100
102
|
- lib/mandrill_mailer/version.rb
|
101
103
|
- mandrill_mailer.gemspec
|
102
104
|
- spec/fake_rails/fake_rails.rb
|
105
|
+
- spec/message_mailer_spec.rb
|
103
106
|
- spec/spec_helper.rb
|
104
107
|
- spec/support/test_image.png
|
105
108
|
- spec/template_mailer_spec.rb
|
@@ -129,6 +132,7 @@ specification_version: 4
|
|
129
132
|
summary: Transactional Mailer for Mandrill
|
130
133
|
test_files:
|
131
134
|
- spec/fake_rails/fake_rails.rb
|
135
|
+
- spec/message_mailer_spec.rb
|
132
136
|
- spec/spec_helper.rb
|
133
137
|
- spec/support/test_image.png
|
134
138
|
- spec/template_mailer_spec.rb
|