From 0b8eb9d767cc7978a49ade3c9f5a647f147914db Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Thu, 9 Jul 2009 16:13:22 +0100 Subject: [PATCH 1/2] 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 36122e2..c275d5a 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -593,7 +593,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 78f3c9e..3b464df 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -861,6 +861,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') @@ -1009,6 +1029,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.5 From 8346185bda31201acff5e0c2847adde181ab2f51 Mon Sep 17 00:00:00 2001 From: Rodrigo Kochenburger Date: Mon, 22 Mar 2010 16:16:18 -0700 Subject: [PATCH 2/2] Set mailer template_root as absolute path --- actionmailer/test/abstract_unit.rb | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/actionmailer/test/abstract_unit.rb b/actionmailer/test/abstract_unit.rb index 9728ae5..0aed45b 100644 --- a/actionmailer/test/abstract_unit.rb +++ b/actionmailer/test/abstract_unit.rb @@ -17,7 +17,7 @@ ActionView::Template.register_template_handler :bak, lambda { |template| "Lame b $:.unshift "#{File.dirname(__FILE__)}/fixtures/helpers" ActionView::Base.cache_template_loading = true -FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures') +FIXTURE_LOAD_PATH = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) ActionMailer::Base.template_root = FIXTURE_LOAD_PATH class MockSMTP -- 1.6.5