Do not forget mailer previews

Posted About 2 years ago. Visible to the public.

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

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|
    describe preview do
      specify "##{mail} works" do
        expect { preview.call(mail) }.not_to raise_error
      end
    end
  end
end

This reminder solves the problem of broken mailer previews.

Niklas Hä.
Last edit
5 days ago
Michael Leimstädtner
Keywords
previews, actionmailer
License
Source code in this card is licensed under the MIT License.
Posted by Niklas Hä. to makandra dev (2022-05-13 06:53)