1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #36227 from betesh/avoid-misleading-error-about-late-attachments

Prevent reading inline attachments after `mail` was called from raising an inaccurate exception
This commit is contained in:
Rafael França 2019-07-26 16:00:44 -04:00 committed by GitHub
commit abaa73f34a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View file

@ -737,7 +737,7 @@ module ActionMailer
end end
class LateAttachmentsProxy < SimpleDelegator class LateAttachmentsProxy < SimpleDelegator
def inline; _raise_error end def inline; self end
def []=(_name, _content); _raise_error end def []=(_name, _content); _raise_error end
private private

View file

@ -267,6 +267,17 @@ class BaseTest < ActiveSupport::TestCase
assert_match(/Can't add attachments after `mail` was called./, e.message) assert_match(/Can't add attachments after `mail` was called./, e.message)
end end
test "accessing inline attachments after mail was called works" do
class LateInlineAttachmentMailer < ActionMailer::Base
def welcome
mail body: "yay", from: "welcome@example.com", to: "to@example.com"
attachments.inline["invoice.pdf"]
end
end
assert_nothing_raised { LateInlineAttachmentMailer.welcome.message }
end
test "adding inline attachments while rendering mail works" do test "adding inline attachments while rendering mail works" do
class LateInlineAttachmentMailer < ActionMailer::Base class LateInlineAttachmentMailer < ActionMailer::Base
def on_render def on_render