filmov
tv
Testing Action Mailer in Rails | Preview
Показать описание
✉️When working with emails, there are quite a few things we want to make sure are working.
First, we want to make sure our design is right. This isn't something we can easily test, so Rails provides Mailer Previews for ActionMailer. We can open our emails up in the browser and simply reload to test our CSS and layout is working how we want it. This isn't perfect because email providers actually strip out CSS, but as long as we stick to what's allowed, this will give us a pretty accurate rendering.
After that, we want to test and make sure that our code is queuing up the emails to be sent out correctly. Rails provides some test helpers to check and make sure the right number of emails were queued and with the right arguments.
Last but not least, we want to test the actual content of our emails. We can use ActionMailer test cases for this. These help make sure your subject lines, to, from, and email body are all correct.
It's not too hard to test your emails in Ruby on Rails. You just need to be thorough since there can be a lot of moving parts!