From 9fec8dad1c80aabda4216ed9588e6510f80c76f8 Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Thu, 9 Jul 2009 16:13:22 +0100 Subject: [PATCH] Fix incorrect relative paths being used when looking up templates. The bug will manifest itself by failing to locate templates when running tests, or when running as a daemon (from /). It relates the the different behavior of ActionView::Template::Path#to_s and ActionView::Template::Path#to_str when a RAILS_ROOT is defined. #to_s reports a path relative to the root, and #to_str reports an absolute path. --- actionmailer/lib/action_mailer/base.rb | 2 +- actionmailer/test/mail_service_test.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index 000c05d..9b39095 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -592,7 +592,7 @@ module ActionMailer #:nodoc: end def template_path - "#{template_root}/#{mailer_name}" + File.join(template_root, mailer_name) end def initialize_template_class(assigns) diff --git a/actionmailer/test/mail_service_test.rb b/actionmailer/test/mail_service_test.rb index 277a913..d0663db 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -824,6 +824,26 @@ EOF assert_equal "text/yaml", mail.parts[2].content_type end + def test_implicitly_path_when_running_from_none_rails_root + exected_path = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "test_mailer")) + with_a_rails_root do + Dir.chdir "/" do + template_path = TestMailer.allocate.send(:template_path) + assert_equal exected_path, File.expand_path(template_path) + end + end + end + + + def test_implicitly_multipart_messages_run_from_another_location_with_a_rails_root + with_a_rails_root do + Dir.chdir "/" do + mail = TestMailer.create_implicitly_multipart_example(@recipient) + assert_equal 3, mail.parts.length + end + end + end + def test_implicitly_multipart_messages_with_charset mail = TestMailer.create_implicitly_multipart_example(@recipient, 'iso-8859-1') @@ -972,6 +992,16 @@ EOF ensure ActionMailer::Base.smtp_settings[:enable_starttls_auto] = true end + +private + def with_a_rails_root + old_root = ::RAILS_ROOT if defined? ::RAILS_ROOT + Object.const_set(:RAILS_ROOT, File.join(File.dirname(__FILE__))) + yield + ensure + Object.send(:remove_const, :RAILS_ROOT) if defined? ::RAILS_ROOT + Object.const_set(:RAILS_ROOT, old_root) if old_root + end end class InheritableTemplateRootTest < Test::Unit::TestCase -- 1.6.3.3.335.g53b74