Skip to content

Instantly share code, notes, and snippets.

@kcurtin
Created April 18, 2013 19:24
Show Gist options
  • Save kcurtin/5415529 to your computer and use it in GitHub Desktop.
Save kcurtin/5415529 to your computer and use it in GitHub Desktop.
Test to ensure there are text versions of all your HTML email templates
describe UserMailer do
it "there is a corresponding text email template for each HTML template" do
# Path to the mailer templates
mailers_path = "#{Rails.root}/app/views/user_mailer/"
result = Dir.foreach(mailers_path) do |template|
# Ignore partials
next if template.match /^_/
# Check if it is an HTML template
html_version = template.match(/.+\.html\..+/)
# Skip if it isn't an HTML template
next unless html_version && html_version[0].present?
# Construct the text version file name
text_version = html_version[0].gsub! "html", "text"
# Check for the text version of the HTML template and return the HTML template if it doesn't exist
break "#{mailers_path}#{html_version}" unless File.exist?("#{mailers_path}#{text_version}")
end
# The block should not return a template with a missing text version
result.should be_nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment