0

我想使用 Action Mailbox TestHelper测试附件。我看到测试助手的选项被传递给邮件对象,但我似乎无法添加附件。他们最终为零。

这就是我所拥有的:

receive_inbound_email_from_mail(
      attachments: [
        File.new(File.join(File.dirname(__FILE__), '../support/fixtures/image.jpeg'))
      ],
      from: 'from@covfefe.test,
      to: 'acme@example.test'
)

它是如何工作的?

4

1 回答 1

0

Edge 支持此功能,但 ActionMailbox::TestHelper 6.0.3.2 尚未实现。

作为一种解决方法,我想出了这个:

subject do
  mail = Mail.new do
    to      'nicolas@test.lindsaar.net.au'
    from    'Mikel Lindsaar <mikel@test.lindsaar.net.au>'
    subject 'First multipart email sent with Mail'

    text_part do
      body 'Here is the attachment you wanted'
    end

    html_part do
      content_type 'text/html; charset=UTF-8'
      body '<h1>Funky Title</h1><p>Here is the attachment you wanted</p>'
    end

    add_file File.join(File.dirname(__FILE__), '../support/fixtures/image.jpeg')
  end

  # Tap the route for processing.
  create_inbound_email_from_source(mail.to_s, status: :processing).tap(&:route)
end

如果您使用的是边缘或更新版本,这应该可以工作:

receive_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

  mail.add_file File.join(File.dirname(__FILE__), '../support/fixtures/image.jpeg')
end

注意:您需要更改文件路径以满足您的需要。和receive_方法相同,create_但它们处理邮件。

于 2020-07-10T01:04:47.567 回答