Spec-Zone.ru › Ruby on Rails 7.2

module ActionMailbox::TestHelper

Открытые методы экземпляра

create_inbound_email_from_fixture(fixture_name, status: :processing) Show source
# 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) Show source
# 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) Show source
# 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) Show source
# 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) Show source
# 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

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

receive_inbound_email_from_source(*args) Show source
# 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

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

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

Spec-Zone.ru

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