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: 'some_email@example.com',
to: 'some_email@example.com',
subject: 'Logo',
body: 'Hi, See the logo attached.',
attachments: [ fixture_file_upload("files/logo.png") ]
)

Reply

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)

Reply

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

Reply

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

Reply

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

Reply
Join the discussion
Create an account Log in

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

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

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