Permalink
Browse files

Ruby 1.9: source encoding, and gem loading issues.

  • Loading branch information...
1 parent 7eee9fb commit e71708135f67608cc0db8b2ffced7a9e42496e0b @grimen committed Aug 30, 2009
Showing with 55 additions and 39 deletions.
  1. +1 −0 lib/convert_entities.rb
  2. +4 −1 lib/helpers.rb
  3. +5 −0 lib/inline_styles.rb
  4. +6 −3 lib/layouts.rb
  5. +18 −19 test/awesome_email_test.rb
  6. +21 −16 test/test_helper.rb
View
@@ -1,3 +1,4 @@
+# coding: utf-8
$KCODE = 'u'
module ActionMailer
View
@@ -1,3 +1,6 @@
+# coding: utf-8
+$KCODE = 'u'
+
module AwesomeEmail
module Helpers
@@ -31,7 +34,7 @@ def setup_multipart_mail
content_type 'text/html'
end
end
-
+
end
end
View
@@ -1,6 +1,11 @@
+# coding: utf-8
+$KCODE = 'u'
+
require 'hpricot'
require 'csspool'
+include CSSPool
+
CSS::SAC::GeneratedParser.send :include, CSS::SAC::Conditions
module ActionMailer
View
@@ -1,3 +1,6 @@
+# coding: utf-8
+$KCODE = 'u'
+
module ActionMailer
module Layouts
module ClassMethods
@@ -6,7 +9,7 @@ module ClassMethods
module InstanceMethods
- # render with layout, if it is set through the "layout" accessor method and a corresponding file is found
+ # render with layout, if it is set through the "layout" accessor method and a corresponding file is found
def render_message_with_layouts(method_name, body)
return render_message_without_layouts(method_name, body) if @layout.blank?
# template was set, now render with layout
@@ -27,7 +30,7 @@ def render_content_for_layout(method_name, template)
file_name = extend_with_mailer_name(method_name)
template.render(:file => file_name)
end
-
+
# finds the layout file and renders it, if the file is not found an exception is raised
# default path for all mailer layouts is layouts/mailers below app/views/
# you can pass in another layout path as 3rd arguments
@@ -62,7 +65,7 @@ def extend_with_mailer_name(template_name)
def self.included(receiver)
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
-
+
receiver.class_eval do
adv_attr_accessor :layout
alias_method_chain :render_message, :layouts
View
@@ -1,10 +1,12 @@
-# enable UTF-8 encoding
+# coding: utf-8
$KCODE = 'u'
-require 'test/unit'
require 'rubygems'
-gem 'actionmailer', '2.3.2'
-gem 'actionpack', '2.3.2'
+gem 'actionmailer', '>= 2.3.2'
+gem 'actionpack', '>= 2.3.2'
+gem 'hpricot'
+gem 'csspool'
+require 'test/unit'
require 'action_mailer'
require 'action_view'
require 'awesome_email'
@@ -13,8 +15,7 @@
ActionMailer::Base.delivery_method = :test
-RAILS_ROOT = '/some/dir'
-
+RAILS_ROOT = '/' << File.join('some', 'dir')
#################################################################
@@ -27,17 +28,17 @@ def test
end
protected
-
+
def setup_multipart_mail
headers 'Content-transfer-encoding' => '8bit'
sent_on Time.now
content_type 'text/html'
end
-
+
def html_part?(method_name)
true
end
-
+
def render_content_for_layout(method_name, template)
'test inner content'
end
@@ -55,11 +56,11 @@ def render_layout_template(template, method_name, layout_path = File.join('layou
class MyMailer
def render_message(method_name, body)
end
-
+
def parse_css_from_file(file_name)
"h1 {font-size:140%}"
end
-
+
def mailer_name
"my_mailer"
end
@@ -71,10 +72,9 @@ def mailer_name
include ActionMailer::Layouts
end
-MyMailer.send(:public, *MyMailer.protected_instance_methods)
+MyMailer.send(:public, *MyMailer.protected_instance_methods)
MyMailer.send(:public, *MyMailer.private_instance_methods)
-
###############################################################
# not so great actually, please do help improve this
@@ -88,7 +88,6 @@ def setup
@mailer = MyMailer.new
end
-
#######################
# inline styles tests #
#######################
@@ -118,7 +117,7 @@ def test_should_add_style_information_found_in_css_file
result = render_inline(html)
assert_not_nil result
assert_not_equal html, result
- assert result =~ /<h1 style="font-size:/
+ assert result =~ /<h1 style="font-size:/
end
def test_should_find_matching_rules
@@ -142,17 +141,17 @@ def test_should_cummulate_style_information
##########################
# convert entities tests #
##########################
-
+
def test_should_replace_entities
expected = '&auml; &Auml;'
result = @mailer.convert_to_entities('ä Ä')
assert_equal expected, result
end
-
+
################
# layout tests #
################
-
+
def test_should_extend_with_mailer_name
template_name = 'some_mail'
result = @mailer.extend_with_mailer_name(template_name)
@@ -178,5 +177,5 @@ def test_should_render_layout_convert_entities_and_apply_css
SimpleMailer.deliver_test
assert SimpleMailer.deliveries.last.body =~ /<h1>F&auml;ncy<\/h1><p>test inner content<\/p>/
end
-
+
end
View
@@ -1,19 +1,24 @@
+# coding: utf-8
+$KCODE = 'u'
+
class Test::Unit::TestCase
- protected
- def find_rules(html)
- css_doc = @mailer.parse_css_doc(@css)
- html_doc = @mailer.parse_html_doc(html)
- css_doc.find_all_rules_matching(html_doc)
- end
-
- def render_inline(html)
- css_doc = @mailer.parse_css_doc(@css)
- html_doc = @mailer.parse_html_doc(html)
- @mailer.render_inline(css_doc, html_doc)
- end
-
- def build_html(content = '', head = '')
- "<html><head>#{head}</head><body>#{content}</body></html>"
- end
+ protected
+
+ def find_rules(html)
+ css_doc = @mailer.parse_css_doc(@css)
+ html_doc = @mailer.parse_html_doc(html)
+ css_doc.find_all_rules_matching(html_doc)
+ end
+
+ def render_inline(html)
+ css_doc = @mailer.parse_css_doc(@css)
+ html_doc = @mailer.parse_html_doc(html)
+ @mailer.render_inline(css_doc, html_doc)
+ end
+
+ def build_html(content = '', head = '')
+ "<html><head>#{head}</head><body>#{content}</body></html>"
+ end
+
end

0 comments on commit e717081

Please sign in to comment.