Spec-Zone.ru › Ruby on Rails 6.1

модуль ActionMailbox::TestHelper

Публичные методы экземпляра

create_inbound_email_from_fixture(fixture_name, status: :processing) Показать исходный код
# 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

Создать запись InboundEmail с помощью фикстуры eml в формате message/rfc822, указанной по ссылке fixture_name в test/fixtures/files/fixture_name.

create_inbound_email_from_mail(status: :processing, **mail_options, &block) Показать исходный код
# 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

Создаёт InboundEmail, задавая параметры через опции или блок.

Опции

  • :status - 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
create_inbound_email_from_source(source, status: :processing) Показать исходный код
# 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

Создать InboundEmail, используя сырой rfc822 source в качестве текста.

receive_inbound_email_from_fixture(*args) Показать исходный код
# 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

Создать InboundEmail из фикстуры, используя те же аргументы, что и create_inbound_email_from_fixture, и немедленно направить его на обработку.

receive_inbound_email_from_mail(**kwargs, &block) Показать исходный код
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 86
def receive_inbound_email_from_mail(**kwargs, &block)
  create_inbound_email_from_mail(**kwargs, &block).tap(&:route)
end

Создать InboundEmail, используя те же опции или блок, что и в create_inbound_email_from_mail, а затем немедленно направить его на обработку.

receive_inbound_email_from_source(*args) Показать исходный код
# File actionmailbox/lib/action_mailbox/test_helper.rb, line 92
def receive_inbound_email_from_source(*args)
  create_inbound_email_from_source(*args).tap(&:route)
end

Создать InboundEmail, используя те же аргументы, что и create_inbound_email_from_source, и немедленно направить его на обработку.

© 2004–2020 David Heinemeier Hansson
Licensed under the MIT License.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API