Added initial email build tests.
This commit is contained in:
parent
4f98f39211
commit
6de94974a5
2 changed files with 54 additions and 0 deletions
|
@ -46,6 +46,10 @@ module Channel::EmailBuild
|
|||
if attr[:content_type] && attr[:content_type] == 'text/html'
|
||||
mail.html_part = Mail::Part.new do
|
||||
content_type 'text/html; charset=UTF-8'
|
||||
|
||||
# complete check
|
||||
attr[:body] = html_complete_check( attr[:body] )
|
||||
|
||||
body attr[:body]
|
||||
end
|
||||
|
||||
|
@ -71,4 +75,29 @@ module Channel::EmailBuild
|
|||
end
|
||||
mail
|
||||
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
|
25
test/unit/email_build_test.rb
Normal file
25
test/unit/email_build_test.rb
Normal 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
|
Loading…
Reference in a new issue