Permalink
Browse files

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.

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information...
1 parent 629afe9 commit 97e07a88feaf334d7eaa44f66bcd57c08cd587a6 @tomlea tomlea committed with josevalim Jul 9, 2009
Showing with 31 additions and 1 deletion.
  1. +1 −1 actionmailer/lib/action_mailer/base.rb
  2. +30 −0 actionmailer/test/mail_service_test.rb
@@ -593,7 +593,7 @@ def template_root=(root)
end
def template_path
- "#{template_root}/#{mailer_name}"
+ File.join(template_root, mailer_name)
end
def initialize_template_class(assigns)
@@ -861,6 +861,26 @@ def test_implicitly_multipart_messages_with_custom_order
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 @@ def test_starttls_is_not_enabled
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

0 comments on commit 97e07a8

Please sign in to comment.