Added initial email build tests.

This commit is contained in:
Martin Edenhofer 2014-12-29 16:39:59 +01:00
parent 4f98f39211
commit 6de94974a5
2 changed files with 54 additions and 0 deletions

View file

@ -46,6 +46,10 @@ module Channel::EmailBuild
if attr[:content_type] && attr[:content_type] == 'text/html' if attr[:content_type] && attr[:content_type] == 'text/html'
mail.html_part = Mail::Part.new do mail.html_part = Mail::Part.new do
content_type 'text/html; charset=UTF-8' content_type 'text/html; charset=UTF-8'
# complete check
attr[:body] = html_complete_check( attr[:body] )
body attr[:body] body attr[:body]
end end
@ -71,4 +75,29 @@ module Channel::EmailBuild
end end
mail mail
end end
=begin
full_html_document_string = Channel::EmailBuild.html_complete_check( html_string )
=end
def self.html_complete_check(html)
return html if html =~ /<html>/i
css = 'font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;'
html = <<HERE
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>'
<head>
<body style="#{css}">
</body>
</html>
HERE
html
end
end end

View file

@ -0,0 +1,25 @@
# encoding: utf-8
require 'test_helper'
class EmailBuildTest < ActiveSupport::TestCase
test 'document complete check' do
html = '<b>test</b>'
result = Channel::EmailBuild.html_complete_check( html )
assert( result =~ /^<\!DOCTYPE/, 'test 1')
assert( result !~ /^.+?<\!DOCTYPE/, 'test 1')
assert( result =~ /<html>/, 'test 1')
assert( result =~ /font-family/, 'test 1')
html = 'invalid <!DOCTYPE html><html><b>test</b></html>'
result = Channel::EmailBuild.html_complete_check( html )
assert( result !~ /^<\!DOCTYPE/, 'test 2')
assert( result =~ /^.+?<\!DOCTYPE/, 'test 2')
assert( result =~ /<html>/, 'test 2')
assert( result !~ /font-family/, 'test 2')
end
end