aboutsummaryrefslogtreecommitdiffstats
path: root/actionmailer/test
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2014-09-22 16:08:17 +0200
committerYves Senn <yves.senn@gmail.com>2014-09-22 16:09:48 +0200
commit7aca4a721ee9ba7f7ba4043f7199080cf7282d62 (patch)
tree06432f8ef34308908003b7d22f3740dcd22dd751 /actionmailer/test
parent748105adccd62ac484cbb4c67c24194b5858055f (diff)
parentb37e8482caee6d406ac5933fceb60cd2b74adfb7 (diff)
downloadrails-7aca4a721ee9ba7f7ba4043f7199080cf7282d62.tar.gz
rails-7aca4a721ee9ba7f7ba4043f7199080cf7282d62.tar.bz2
rails-7aca4a721ee9ba7f7ba4043f7199080cf7282d62.zip
Merge pull request #16974 from silp-com/mail_was_called
ActionMailer: mark mail as called after instead of before processing it
Diffstat (limited to 'actionmailer/test')
-rw-r--r--actionmailer/test/base_test.rb14
-rw-r--r--actionmailer/test/fixtures/base_test/late_inline_attachment_mailer/on_render.erb7
2 files changed, 21 insertions, 0 deletions
diff --git a/actionmailer/test/base_test.rb b/actionmailer/test/base_test.rb
index d00f5aea47..dcb6959543 100644
--- a/actionmailer/test/base_test.rb
+++ b/actionmailer/test/base_test.rb
@@ -259,6 +259,20 @@ class BaseTest < ActiveSupport::TestCase
assert_match(/Can't add attachments after `mail` was called./, e.message)
end
+ test "adding inline attachments while rendering mail works" do
+ class LateInlineAttachmentMailer < ActionMailer::Base
+ def on_render
+ mail from: "welcome@example.com", to: "to@example.com"
+ end
+ end
+
+ mail = LateInlineAttachmentMailer.on_render
+ assert_nothing_raised { mail.message }
+
+ assert_equal ["image/jpeg; filename=controller_attachments.jpg",
+ "image/jpeg; filename=attachments.jpg"], mail.attachments.inline.map {|a| a['Content-Type'].to_s }
+ end
+
test "accessing attachments works after mail was called" do
class LateAttachmentAccessorMailer < ActionMailer::Base
def welcome
diff --git a/actionmailer/test/fixtures/base_test/late_inline_attachment_mailer/on_render.erb b/actionmailer/test/fixtures/base_test/late_inline_attachment_mailer/on_render.erb
new file mode 100644
index 0000000000..6decd3bb31
--- /dev/null
+++ b/actionmailer/test/fixtures/base_test/late_inline_attachment_mailer/on_render.erb
@@ -0,0 +1,7 @@
+<h1>Adding an inline image while rendering</h1>
+
+<% controller.attachments.inline["controller_attachments.jpg"] = 'via controller.attachments.inline' %>
+<%= image_tag attachments['controller_attachments.jpg'].url %>
+
+<% attachments.inline["attachments.jpg"] = 'via attachments.inline' %>
+<%= image_tag attachments['attachments.jpg'].url %>