Skip to main content

How to test attachments in ActionMailbox?

Rails • Asked by Lidia Wisniewska

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.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.