From ea17a5a65fd38c876e0889d31da5ba36ca30abe1 Mon Sep 17 00:00:00 2001 From: thedarkone Date: Mon, 6 Apr 2009 21:52:29 +0200 Subject: [PATCH] Fix implicit multipart mailer views when RAILS_ROOT != pwd. [#2263 state:resolved] --- actionmailer/lib/action_mailer/base.rb | 4 ++-- actionmailer/test/mail_service_test.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/actionmailer/lib/action_mailer/base.rb b/actionmailer/lib/action_mailer/base.rb index b77409b..d613b86 100644 --- a/actionmailer/lib/action_mailer/base.rb +++ b/actionmailer/lib/action_mailer/base.rb @@ -465,7 +465,7 @@ module ActionMailer #:nodoc: # "the_template_file.text.html.erb", etc.). Only do this if parts # have not already been specified manually. if @parts.empty? - Dir.glob("#{template_path}/#{@template}.*").each do |path| + Dir.glob("#{template_path}/#{@template}.*") do |path| template = template_root["#{mailer_name}/#{File.basename(path)}"] # Skip unless template has a multipart format @@ -592,7 +592,7 @@ module ActionMailer #:nodoc: end def template_path - "#{template_root}/#{mailer_name}" + "#{template_root.path}/#{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..3e0dd63 100644 --- a/actionmailer/test/mail_service_test.rb +++ b/actionmailer/test/mail_service_test.rb @@ -834,6 +834,21 @@ EOF assert_equal 'iso-8859-1', mail.parts[2].sub_header("content-type", "charset") end + def test_implicitly_multipart_messages_are_not_broken_by_chdir + # use absolute path for mailer template_root + old_template_root, TestMailer.template_root = TestMailer.template_root, File.expand_path(TestMailer.template_root) + # we have to have RAILS_ROOT const set to reproduce the faulty behavior + old_rails_root = ::RAILS_ROOT if defined?(::RAILS_ROOT) + silence_warnings { Object.const_set(:RAILS_ROOT, Dir.pwd) } + + Dir.chdir('..') do + assert_equal 3, TestMailer.create_implicitly_multipart_example(@recipient, nil, ["text/yaml", "text/plain"]).parts.length + end + ensure + TestMailer.template_root = old_template_root + old_rails_root ? silence_warnings { Object.const_set(:RAILS_ROOT, old_rails_root) } : Object.send(:remove_const, :RAILS_ROOT) + end + def test_html_mail mail = TestMailer.create_html_mail(@recipient) assert_equal "text/html", mail.content_type -- 1.6.0.1