File tree 2 files changed +35
-3
lines changed
2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -233,15 +233,17 @@ def build_mail(options)
233
233
# we need to explicitly define a second multipart/alternative
234
234
# boundary to encapsulate the body-parts within the
235
235
# multipart/mixed boundary that will be created automatically.
236
- if options [ :attachments ] && options [ :html_body ] && options [ :body ]
236
+ options [ :attachments ] ||= { }
237
+
238
+ if options [ :attachments ] . any? && options [ :html_body ] && options [ :body ]
237
239
mail . part ( :content_type => 'multipart/alternative' ) do |p |
238
240
p . html_part = build_html_part ( options )
239
241
p . text_part = build_text_part ( options )
240
242
end
241
243
242
244
# Otherwise if there is more than one part we still need to
243
245
# ensure that they are all declared to be separate.
244
- elsif options [ :html_body ] || options [ :attachments ]
246
+ elsif options [ :html_body ] || options [ :attachments ] . any?
245
247
mail . html_part = build_html_part ( options ) if options [ :html_body ]
246
248
mail . text_part = build_text_part ( options ) if options [ :body ]
247
249
@@ -254,7 +256,7 @@ def build_mail(options)
254
256
mail [ key ] = value
255
257
end
256
258
257
- add_attachments ( mail , options [ :attachments ] ) if options [ :attachments ]
259
+ add_attachments ( mail , options [ :attachments ] ) if options [ :attachments ] . any?
258
260
259
261
mail . charset = options [ :charset ] if options [ :charset ] # charset must be set after setting content_type
260
262
Original file line number Diff line number Diff line change 301
301
end
302
302
303
303
describe "content type" do
304
+ shared_examples 'a mail with only html_body and body set' do
305
+ it { expect ( mail . parts . length ) . to eq 2 }
306
+ it { expect ( mail . content_type . to_s ) . to include ( 'multipart/alternative' ) }
307
+ it { expect ( mail . parts [ 0 ] . to_s ) . to include ( 'Content-Type: text/html' ) }
308
+ it { expect ( mail . parts [ 1 ] . to_s ) . to include ( 'Content-Type: text/plain' ) }
309
+ end
310
+
311
+ context "mail html_body and body" do
312
+ subject ( :mail ) do
313
+ Pony . send ( :build_mail ,
314
+ :body => 'test' ,
315
+ :html_body => 'What do you know, Joe?' ,
316
+ )
317
+ end
318
+
319
+ it_behaves_like 'a mail with only html_body and body set'
320
+ end
321
+
304
322
context "mail with attachments, html_body and body " do
305
323
subject ( :mail ) do
306
324
Pony . send ( :build_mail ,
318
336
it { expect ( mail . parts [ 0 ] . parts [ 1 ] . to_s ) . to include ( 'Content-Type: text/plain' ) }
319
337
it { expect ( mail . parts [ 1 ] . to_s ) . to include ( 'Content-Type: text/plain' ) }
320
338
end
339
+
340
+ context "mail html_body and body and empty attachment list" do
341
+ subject ( :mail ) do
342
+ Pony . send ( :build_mail ,
343
+ :body => 'test' ,
344
+ :html_body => 'What do you know, Joe?' ,
345
+ :attachments => { } ,
346
+ )
347
+ end
348
+
349
+ it_behaves_like 'a mail with only html_body and body set'
350
+ end
321
351
end
322
352
323
353
describe "additional headers" do
You can’t perform that action at this time.
0 commit comments