From 081306d053f828d0cac620a717978c82adf2a77a Mon Sep 17 00:00:00 2001 From: Guilherme Cavalcanti Date: Mon, 10 Oct 2011 21:27:04 -0300 Subject: [PATCH] Two-phase conversion to avoid requests deadlocks. Closes #4 --- lib/action_mailer/inline_css_hook.rb | 10 ++++++++-- test/premailer_stylesheet_link_tag_test.rb | 7 +++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/action_mailer/inline_css_hook.rb b/lib/action_mailer/inline_css_hook.rb index a4c6d79..4d83524 100644 --- a/lib/action_mailer/inline_css_hook.rb +++ b/lib/action_mailer/inline_css_hook.rb @@ -5,9 +5,15 @@ module ActionMailer class InlineCssHook def self.delivering_email(message) if html_part = (message.html_part || (message.content_type =~ /text\/html/ && message)) + # Generate an email with all CSS inlined (access CSS a FS path) premailer = ::Premailer.new(html_part.body.to_s, - :with_html_string => true, - :base_url => message.header[:host].to_s) + :with_html_string => true) + + # Prepend host to remaning URIs. + # Two-phase conversion to avoid request deadlock from dev. server (Issue #4) + premailer = ::Premailer.new(premailer.to_inline_css, + :with_html_string => true, + :base_url => message.header[:host].to_s) existing_text_part = message.text_part && message.text_part.body.to_s # Reset the body message.body = nil diff --git a/test/premailer_stylesheet_link_tag_test.rb b/test/premailer_stylesheet_link_tag_test.rb index 8b8b3a2..c18f235 100644 --- a/test/premailer_stylesheet_link_tag_test.rb +++ b/test/premailer_stylesheet_link_tag_test.rb @@ -30,10 +30,9 @@ def mail_with_defaults(&block) class PremailerStylesheetLinkTagTest < ActionMailer::TestCase def test_premailer_stylesheet_link_tag - stub_request(:get, /example\.com\/*/).to_return do - css = "div.test { color: #119911; }" - { :status => 200, :body => css } - end + css_file = "div.test { color: #119911; }" + File.stubs(:exist?).returns(true) + File.stubs(:read).returns(css_file) mail = HelperMailer.use_stylesheet_link_tag.deliver assert_match "
", mail.html_part.body.encoded