New Discussion

Notifications

You’re not receiving notifications from this thread.

How to test attachments in ActionMailbox?

4
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: 'some_email@example.com',
to: 'some_email@example.com',
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: 'some_email@example.com',
to: 'some_email@example.com',
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
Create an account Log in

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

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

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