All threads / How to test attachments in ActionMailbox?

Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to test attachments in ActionMailbox?

Lidia Wisniewska asked in Rails

I'm trying to test attachments using receive_inbound_email_from_mail, but when inspecting mail.attachments I get an empty array. Is there another way around this?
receive_inbound_email_from_mail(
from: '[email protected]',
to: '[email protected]',
subject: 'Logo',
body: 'Hi, See the logo attached.',
attachments: [ fixture_file_upload("files/logo.png") ]
)

It turns out this is the way to go
mail = Mail.new(
from: '[email protected]',
to: '[email protected]',
subject: 'Logo',
body: 'Hi, See the logo attached.',
)
mail.add_file filename: 'sample.txt', content: StringIO.new('Sample Logo')
create_inbound_email_from_source(mail.to_s, status: :processing).tap(&:route)

Thanks for posting the solution! I'm going to be covering this soon so I might use your example here. 🙌

Awesome! It was actually my teammate who got to this solution in the end.

Thank you posting this. It helped us cover attachment test cases.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.