方法
- C
- R
实例公共方法
create_inbound_email_from_fixture(fixture_name, status: :processing) 链接
使用格式为 message/rfc822 的 eml 固件创建一个 InboundEmail 记录,该固件在 test/fixtures/files/fixture_name 中通过 fixture_name 引用。
来源: 显示 | 在 GitHub 上
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 9 def create_inbound_email_from_fixture(fixture_name, status: :processing) create_inbound_email_from_source file_fixture(fixture_name).read, status: status end
create_inbound_email_from_mail(status: :processing, **mail_options, &block) 链接
通过选项或块来创建 InboundEmail。
选项¶ ↑
-
:status- 为创建的InboundEmail设置的状态。有关可能的状态,请参阅其文档。
创建简单邮件¶ ↑
当您只需要设置基本字段,如 from、to、subject 和 body 时,您可以直接将它们作为选项传递。
create_inbound_email_from_mail(from: "david@loudthinking.com", subject: "Hello!")
创建多部分邮件¶ ↑
当您需要创建更复杂的邮件,例如包含纯文本版本和 HTML 版本的多部分邮件时,您可以传递一个块。
create_inbound_email_from_mail do to "David Heinemeier Hansson <david@loudthinking.com>" from "Bilbo Baggins <bilbo@bagend.com>" subject "Come down to the Shire!" text_part do body "Please join us for a party at Bag End" end html_part do body "<h1>Please join us for a party at Bag End</h1>" end end
与 Mail.new 一样,您也可以使用块参数来定义消息的各个部分
create_inbound_email_from_mail do |mail| mail.to "David Heinemeier Hansson <david@loudthinking.com>" mail.from "Bilbo Baggins <bilbo@bagend.com>" mail.subject "Come down to the Shire!" mail.text_part do |part| part.body "Please join us for a party at Bag End" end mail.html_part do |part| part.body "<h1>Please join us for a party at Bag End</h1>" end end
来源: 显示 | 在 GitHub 上
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 63 def create_inbound_email_from_mail(status: :processing, **mail_options, &block) mail = Mail.new(mail_options, &block) # Bcc header is not encoded by default mail[:bcc].include_in_headers = true if mail[:bcc] create_inbound_email_from_source mail.to_s, status: status end
create_inbound_email_from_source(source, status: :processing) 链接
使用原始 rfc822 source 作为文本创建一个 InboundEmail。
来源: 显示 | 在 GitHub 上
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 72 def create_inbound_email_from_source(source, status: :processing) ActionMailbox::InboundEmail.create_and_extract_message_id! source, status: status end
receive_inbound_email_from_fixture(*args) 链接
使用与 create_inbound_email_from_fixture 相同的参数,从固件创建 InboundEmail,并立即将其路由到处理。
来源: 显示 | 在 GitHub 上
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 79 def receive_inbound_email_from_fixture(*args) create_inbound_email_from_fixture(*args).tap(&:route) end
receive_inbound_email_from_mail(**kwargs, &block) 链接
使用与 create_inbound_email_from_mail 相同的选项或块创建 InboundEmail,然后立即将其路由进行处理。
来源: 显示 | 在 GitHub 上
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 85 def receive_inbound_email_from_mail(**kwargs, &block) create_inbound_email_from_mail(**kwargs, &block).tap(&:route) end
receive_inbound_email_from_source(*args) 链接
使用与 create_inbound_email_from_source 相同的参数创建一个 InboundEmail,并立即将其路由到处理。
来源: 显示 | 在 GitHub 上
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 91 def receive_inbound_email_from_source(*args) create_inbound_email_from_source(*args).tap(&:route) end