Created
April 18, 2013 19:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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