mandrill_mailer 0.6.1 → 1.0.0

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.
@@ -1,148 +1,27 @@
1
1
  require "spec_helper"
2
- require 'base64'
3
2
 
4
3
  describe MandrillMailer::MessageMailer do
5
- let(:image_path) { '/assets/image.jpg' }
6
- let(:default_host) { 'localhost:3000' }
7
4
  let(:mailer) { described_class.new }
8
5
  let(:api_key) { '1237861278' }
9
6
 
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
7
  before do
65
8
  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
9
  end
72
10
 
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
11
+ describe "#deliver" do
12
+ let(:async) { double(:async) }
13
+ let(:ip_pool) { double(:ip_pool) }
14
+ let(:send_at) { double(:send_at) }
15
+ let(:message) { double(:message) }
103
16
 
104
- after do
105
- MandrillMailer.config.interceptor_params = nil
106
- end
17
+ it "calls the messages api with #send" do
18
+ mailer.async = async
19
+ mailer.ip_pool = ip_pool
20
+ mailer.send_at = send_at
21
+ mailer.message = message
107
22
 
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
-
23
+ expect_any_instance_of(Mandrill::Messages).to receive(:send).with(message, async, ip_pool, send_at)
24
+ mailer.deliver
144
25
  end
145
26
  end
146
-
147
-
148
27
  end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'rspec'
2
2
  require 'mandrill_mailer'
3
+ require "mandrill"
4
+
3
5
  require 'pry'
4
6
 
5
7
  # Requires supporting files with custom matchers and macros, etc,
@@ -1,471 +1,53 @@
1
1
  require "spec_helper"
2
- require 'base64'
3
2
 
4
3
  describe MandrillMailer::TemplateMailer do
5
- let(:image_path) { '/assets/image.jpg' }
6
- let(:default_host) { 'localhost:3000' }
7
4
  let(:mailer) { described_class.new }
8
5
  let(:api_key) { '1237861278' }
9
6
 
10
- let(:template_content_name) { 'edit' }
11
- let(:template_content_content) { 'edit_content' }
12
- let(:from_email) { 'from@email.com' }
13
- let(:from_name) { 'Example Name' }
14
- let(:var_name) { 'USER_NAME' }
15
- let(:var_content) { 'bobert' }
16
- let(:var_rcpt_name) { 'USER_INFO' }
17
- let(:var_rcpt_content) { 'boboblacksheep' }
18
- let(:to_email) { 'bob@email.com' }
19
- let(:to_name) { 'bob' }
20
- let(:attachment_file) { File.read(File.expand_path('spec/support/test_image.png')) }
21
- let(:attachment_filename) { 'test_image.png' }
22
- let(:attachment_mimetype) { 'image/png' }
23
-
24
- let(:image_file) { File.read(File.expand_path('spec/support/test_image.png')) }
25
- let(:image_filename) { 'test_image.png' }
26
- let(:image_mimetype) { 'image/png' }
27
-
28
- let(:send_at) { Time.utc(2020, 1, 1, 8, 0) }
29
- let(:bcc) { "bcc@email.com" }
7
+ let(:template_content_name) { "test_template" }
8
+ let(:template_content_content) {"some testing content"}
30
9
 
31
10
  let(:args) do
32
11
  {
33
- from: from_email,
34
12
  template: 'Email Template',
35
- subject: "super secret",
36
- to: {'email' => to_email, 'name' => to_name},
37
- preserve_recipients: false,
38
- vars: {
39
- var_name => var_content
40
- },
41
- recipient_vars: [
42
- { to_email => { var_rcpt_name => var_rcpt_content } }
43
- ],
44
- template_content: {template_content_name => template_content_content},
45
- headers: {"Reply-To" => "support@email.com"},
46
- bcc: bcc,
47
- tags: ['tag1'],
48
- subaccount: "subaccount1",
49
- google_analytics_domains: ["http://site.com"],
50
- google_analytics_campaign: '1237423474',
51
- attachments: [{file: attachment_file, filename: attachment_filename, mimetype: attachment_mimetype}],
52
- images: [{file: image_file, filename: image_filename, mimetype: image_mimetype}],
53
- inline_css: true,
54
- important: true,
55
- send_at: send_at,
56
- track_opens: false,
57
- track_clicks: false,
58
- url_strip_qs: false
59
- }
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
13
+ template_content: {template_content_name => template_content_content}
92
14
  }
93
15
  end
94
16
 
95
17
  before do
96
18
  MandrillMailer.config.api_key = api_key
97
- MandrillMailer.config.default_url_options = { host: default_host }
98
- #MandrillMailer.config.stub(:image_path).and_return(image_path)
99
- allow(MandrillMailer.config).to receive(:image_path).and_return(image_path)
100
-
101
- MandrillMailer::TemplateMailer.default from: from_email, from_name: from_name
102
- end
103
-
104
- describe '#image_path' do
105
- subject { mailer.image_path('logo.png') }
106
-
107
- context 'Rails exists' do
108
- let(:image) { 'image.png' }
109
- let(:host) { 'codeschool.com' }
110
- let(:router) { Rails.application.routes.url_helpers }
111
-
112
- before do
113
- # use load instead of require since we have to reload for every test
114
- mailer.send(:load, 'fake_rails/fake_rails.rb')
115
- MandrillMailer.config.default_url_options[:host] = host
116
- end
117
-
118
- # Essentially un-requiring the fake rails class so it doesn't pollute
119
- # the rest of the tests
120
- after do
121
- Rails.unload!
122
- end
123
-
124
- it 'should return the image url' do
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))
127
- end
128
- end
129
-
130
- context 'Rails does not exist' do
131
- it 'should raise exception' do
132
- expect{ subject }.to raise_error
133
- end
134
- end
135
- end
136
-
137
- describe '#mandrill_args' do
138
- let(:arg_name) { 'USER_NAME' }
139
- let(:arg_value) { 'bob' }
140
-
141
- subject { mailer.send(:mandrill_args, {arg_name => arg_value}) }
142
-
143
- it 'should convert the args to the correct format' do
144
- should eq [{'name' => arg_name, 'content' => arg_value}]
145
- end
146
- end
147
-
148
- describe '#mandrill_rcpt_args' do
149
- let(:rcpt) { 'email@email.com' }
150
- let(:arg_name) { 'USER_NAME' }
151
- let(:arg_value) { 'bob' }
152
-
153
- subject { mailer.send(:mandrill_rcpt_args, [{rcpt => {arg_name => arg_value}}]) }
154
-
155
- it 'should convert the args to the merge_vars format' do
156
- should eq [{'rcpt' => rcpt, 'vars' => [{'name' => arg_name, 'content' => arg_value}]}]
157
- end
158
19
  end
159
20
 
160
- describe '#format_boolean' do
161
- it 'only returns true or false' do
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
167
- end
168
- end
169
-
170
- describe '#format_to_params' do
171
- let(:email) { 'bob@email.com' }
172
- let(:name) { 'bob' }
173
-
174
- context 'with a single email string' do
175
- subject { mailer.send(:format_to_params, email) }
176
-
177
- it 'should format args to a format mandrill likes' do
178
- should eq [{"email" => email, "name" => email}]
179
- end
180
- end
181
-
182
- context 'with a single email string array' do
183
- subject { mailer.send(:format_to_params, [email]) }
184
-
185
- it 'should format args to a format mandrill likes' do
186
- should eq [{"email" => email, "name" => email}]
187
- end
188
- end
189
-
190
- context 'with a single email/name Hash' do
191
- subject { mailer.send(:format_to_params, {"email" => email, "name" => name}) }
192
-
193
- it 'should format args to a format mandrill likes' do
194
- should eq [{"email" => email, "name" => name}]
195
- end
196
- end
197
-
198
- context 'with a single email/name hash Array' do
199
- subject { mailer.send(:format_to_params, [{"email" => email, "name" => name}]) }
200
-
201
- it 'should format args to a format mandrill likes' do
202
- should eq [{"email" => email, "name" => name}]
203
- end
204
- end
205
- end
206
-
207
- describe '#mandrill_mail' do
208
- subject { mailer.mandrill_mail(args) }
209
-
210
- it 'should return the current class instance' do
211
- should eq mailer
212
- end
213
-
21
+ describe '#mandrill_mail_handler' do
214
22
  it 'should set the template name' do
215
- expect(subject.template_name).to eq 'Email Template'
23
+ mailer.mandrill_mail_handler(args)
24
+ expect(mailer.template_name).to eq 'Email Template'
216
25
  end
217
26
 
218
-
219
27
  it 'should set the template content' do
220
- expect(subject.template_content).to eq [{'name' => template_content_name, 'content' => template_content_content}]
221
- end
222
-
223
- it 'should retain data method' do
224
- expect(subject.data).to eq({
225
- "key" => MandrillMailer.config.api_key,
226
- "template_name" => subject.template_name,
227
- "template_content" => subject.template_content,
228
- "message" => subject.message,
229
- "async" => subject.async,
230
- "ip_pool" => subject.ip_pool,
231
- "send_at" => subject.send_at
232
- })
233
- end
234
-
235
- it 'should set send_at option' do
236
- expect(subject.send_at).to eq('2020-01-01 08:00:00')
237
- end
238
-
239
- context "without interceptor" do
240
- it 'should produce the correct message' do
241
- expect(subject.message).to eq ({
242
- "subject" => args[:subject],
243
- "from_email" => from_email,
244
- "from_name" => from_name,
245
- "to" => [{'email' => to_email, 'name' => to_name}],
246
- "headers" => args[:headers],
247
- "important" => args[:important],
248
- "inline_css" => args[:inline_css],
249
- "track_opens" => args[:track_opens],
250
- "track_clicks" => args[:track_clicks],
251
- "auto_text" => true,
252
- "url_strip_qs" => args[:url_strip_qs],
253
- "preserve_recipients" => false,
254
- "bcc_address" => args[:bcc],
255
- "merge_language" => args[:merge_language],
256
- "global_merge_vars" => [{"name" => var_name, "content" => var_content}],
257
- "merge_vars" => [{"rcpt" => to_email, "vars" => [{"name" => var_rcpt_name, "content" => var_rcpt_content}]}],
258
- "tags" => args[:tags],
259
- "metadata" => args[:metadata],
260
- "subaccount" => args[:subaccount],
261
- "google_analytics_domains" => args[:google_analytics_domains],
262
- "google_analytics_campaign" => args[:google_analytics_campaign],
263
- "attachments" => [{'type' => attachment_mimetype, 'name' => attachment_filename, 'content' => Base64.encode64(attachment_file)}],
264
- "images" => [{'type' => image_mimetype, 'name' => image_filename, 'content' => Base64.encode64(image_file)}]
265
- })
266
- end
267
- end
268
-
269
- context "with interceptor" do
270
- before(:each) do
271
- @intercepted_params = {
272
- to: [{ email: 'interceptedto@test.com', name: 'Mr. Interceptor' }],
273
- tags: ['intercepted-tag'],
274
- bcc_address: 'interceptedbbc@email.com'
275
- }
276
- MandrillMailer.config.interceptor_params = @intercepted_params
277
- end
278
-
279
- after do
280
- MandrillMailer.config.interceptor_params = nil
281
- end
282
-
283
- it "should raise an error if interceptor params is not a Hash" do
284
- MandrillMailer.config.interceptor_params = "error"
285
- expect { subject }.to raise_error(MandrillMailer::TemplateMailer::InvalidInterceptorParams, "The interceptor_params config must be a Hash")
286
- end
287
-
288
- it 'should produce the correct message' do
289
- expect(subject.message).to eq ({
290
- "subject" => args[:subject],
291
- "from_email" => from_email,
292
- "from_name" => from_name,
293
- "to" => @intercepted_params[:to],
294
- "headers" => args[:headers],
295
- "important" => args[:important],
296
- "inline_css" => args[:inline_css],
297
- "track_opens" => args[:track_opens],
298
- "track_clicks" => args[:track_clicks],
299
- "auto_text" => true,
300
- "url_strip_qs" => args[:url_strip_qs],
301
- "preserve_recipients" => false,
302
- "bcc_address" => @intercepted_params[:bcc_address],
303
- "merge_language" => args[:merge_language],
304
- "global_merge_vars" => [{"name" => var_name, "content" => var_content}],
305
- "merge_vars" => [{"rcpt" => to_email, "vars" => [{"name" => var_rcpt_name, "content" => var_rcpt_content}]}],
306
- "tags" => @intercepted_params[:tags],
307
- "metadata" => args[:metadata],
308
- "subaccount" => args[:subaccount],
309
- "google_analytics_domains" => args[:google_analytics_domains],
310
- "google_analytics_campaign" => args[:google_analytics_campaign],
311
- "attachments" => [{'type' => attachment_mimetype, 'name' => attachment_filename, 'content' => Base64.encode64(attachment_file)}],
312
- "images" => [{'type' => image_mimetype, 'name' => image_filename, 'content' => Base64.encode64(image_file)}]
313
- })
314
- end
315
- end
316
- end
317
-
318
-
319
- describe 'url helpers in mailer' do
320
- subject { mailer.send(:course_url) }
321
-
322
- context 'Rails is defined (Rails app)' do
323
- let(:url) { '/courses/1' }
324
- let(:host) { 'codeschool.com' }
325
- let(:router) { Rails.application.routes.url_helpers }
326
-
327
- before do
328
- # use load since we are loading multiple times
329
- mailer.send(:load, 'fake_rails/fake_rails.rb')
330
- MandrillMailer.config.default_url_options[:host] = host
331
- Rails.application.routes.draw do |builder|
332
- builder.course_url "#{url}"
333
- end
334
- end
335
-
336
- # Essentially un-requiring the fake rails class so it doesn't pollute
337
- # the rest of the tests
338
- after do
339
- Rails.unload!
340
- end
341
-
342
- it 'should return the correct route' do
343
- expect(subject).to eq router.course_url(host: host)
344
- end
345
-
346
- context 'route helper with an argument' do
347
- it 'should return the correct route' do
348
- expect(subject).to eq router.course_url({id: 1, title: 'zombies'}, host: host)
349
- end
350
- end
351
- end
352
-
353
- context 'Rails is not defined' do
354
- it 'should raise an exception' do
355
- expect{subject}.to raise_error
356
- end
357
- end
358
- end
359
-
360
- describe 'defaults' do
361
- it 'should not share between different subclasses' do
362
- klassA = Class.new(MandrillMailer::TemplateMailer) do
363
- default from_name: 'ClassA', merge_vars: { 'FOO' => 'Bar' }
364
- end
365
- klassB = Class.new(MandrillMailer::TemplateMailer) do
366
- default from_name: 'ClassB'
367
- end
368
-
369
- expect(klassA.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassA'
370
- expect(klassA.mandrill_mail({vars: {}}).message['global_merge_vars']).to include({"name"=>"FOO", "content"=>"Bar"})
371
- expect(klassB.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassB'
372
- expect(klassB.mandrill_mail({vars: {}}).message['global_merge_vars']).to_not include({"name"=>"FOO", "content"=>"Bar"})
373
- end
374
-
375
- it 'should use defaults from the parent class' do
376
- klassA = Class.new(MandrillMailer::TemplateMailer) do
377
- default from_name: 'ClassA', merge_vars: { 'FOO' => 'Bar' }
378
- end
379
- klassB = Class.new(klassA) do
380
- end
381
-
382
- expect(klassB.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassA'
383
- expect(klassB.mandrill_mail({vars: {}}).message['global_merge_vars']).to include({"name"=>"FOO", "content"=>"Bar"})
384
- end
385
-
386
- it 'should allow overriding defaults from the parent' do
387
- klassA = Class.new(MandrillMailer::TemplateMailer) do
388
- default from_name: 'ClassA', merge_vars: { 'FOO' => 'Bar' }
389
- end
390
- klassB = Class.new(klassA) do
391
- default from_name: 'ClassB', merge_vars: { 'FOO' => 'Boo' }
392
- end
393
-
394
- expect(klassB.mandrill_mail({vars: {}}).message['from_name']).to eq 'ClassB'
395
- expect(klassB.mandrill_mail({vars: {}}).message['global_merge_vars']).to include({"name"=>"FOO", "content"=>"Boo"})
28
+ mailer.mandrill_mail_handler(args)
29
+ expect(mailer.template_content).to eq [{'name' => template_content_name, 'content' => template_content_content}]
396
30
  end
397
31
  end
398
32
 
399
- describe '#respond_to' do
400
- it 'can respond to a symbol' do
401
- klassA = Class.new(MandrillMailer::TemplateMailer) do
402
- def test_method
403
-
404
- end
405
- end
406
-
407
- expect(klassA).to respond_to('test_method')
408
- end
409
- it 'can respond to a string' do
410
- klassA = Class.new(MandrillMailer::TemplateMailer) do
411
- def test_method
412
-
413
- end
414
- end
415
-
416
- expect(klassA).to respond_to('test_method')
417
- end
418
- end
419
-
420
- describe "#from" do
421
- subject { mailer.mandrill_mail(args) }
422
-
423
- it "returns the from email" do
424
- expect(subject.from).to eq from_email
425
- end
426
- end
427
-
428
- describe "#to" do
429
- subject { mailer.mandrill_mail(args) }
430
-
431
- it "returns the to email data" do
432
- expect(subject.to).to eq [{"email" => to_email, "name" => to_name}]
433
- end
434
- end
435
-
436
- describe '#to=' do
437
- subject { mailer.mandrill_mail(args) }
438
-
439
- it "updates the to email data" do
440
- subject.to = 'bob@example.com'
441
- expect(subject.to).to eq [{"email" => "bob@example.com", "name" => "bob@example.com"}]
442
- end
443
- end
444
-
445
- describe "#bcc" do
446
- subject { mailer.mandrill_mail(args) }
447
-
448
- it "returns the bcc email/s" do
449
- expect(subject.bcc).to eq bcc
450
- end
451
- end
452
-
453
- describe "#vars" do
454
- subject { mailer.mandrill_mail(args) }
455
-
456
- it "returns the vars" do
457
- expect(subject.message["global_merge_vars"].first.values).to include(var_name)
458
- expect(subject.message["global_merge_vars"].first.values).to include(var_content)
459
- end
33
+ describe "#deliver" do
34
+ let(:async) { double(:async) }
35
+ let(:ip_pool) { double(:ip_pool) }
36
+ let(:send_at) { double(:send_at) }
37
+ let(:message) { double(:message) }
38
+ let(:template_name) { double(:template_name) }
39
+ let(:template_content) { double(:template_content) }
460
40
 
461
- context "when no vars are set" do
462
- before do
463
- args.delete(:vars)
464
- end
41
+ it "calls the messages api with #send_template" do
42
+ mailer.async = async
43
+ mailer.ip_pool = ip_pool
44
+ mailer.send_at = send_at
45
+ mailer.message = message
46
+ mailer.template_content = template_content
47
+ mailer.template_name = template_name
465
48
 
466
- it "doesn't explode" do
467
- expect { subject }.not_to raise_error
468
- end
49
+ expect_any_instance_of(Mandrill::Messages).to receive(:send_template).with(template_name, template_content, message, async, ip_pool, send_at)
50
+ mailer.deliver
469
51
  end
470
52
  end
471
53
  end