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

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

@ -267,6 +267,17 @@ def welcome
assert_match(/Can't add attachments after `mail` was called./, e.message)
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
class LateInlineAttachmentMailer < ActionMailer::Base
def on_render