Read more

Do not forget mailer previews

Niklas Hä.
May 13, 2022Software engineer at makandra GmbH

When changing code in mailers, updating the corresponding mailer preview is easily forgotten.

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Mailer previews can be tested like other code as well and I sometimes add the following test to test suites:

# Make sure to require the previews
Dir[Rails.root.join('test/mailers/previews/*.rb')].sort.each { |file| require(file) }


ActionMailer::Preview.all.index_with(&:emails).each do |preview, mails|
  mails.each do |mail|
    it "#{preview}##{mail} works" do
      expect { preview.call(mail) }.not_to raise_error
    end
  end
end

This reminder solves the problem of broken mailer previews.

Posted by Niklas Hä. to makandra dev (2022-05-13 08:53)