Skip to content
This repository
Browse code

Update ActionMailer so it treats ActionView the same way that ActionC…

…ontroller does. Closes #10244 [rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8212 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit bd5ed651105663cb4bc5acd86ad8bdf48251d0fe 1 parent 3d67860
risk danger olson authored November 26, 2007
5  actionmailer/CHANGELOG
... ...
@@ -1,5 +1,10 @@
1 1
 *SVN*
2 2
 
  3
+* Update ActionMailer so it treats ActionView the same way that ActionController does.  Closes #10244 [rick]
  4
+
  5
+  * Pass the template_root as an array as ActionView's view_path
  6
+  * Request templates with the "#{mailer_name}/#{action}" as opposed to just "#{action}"
  7
+
3 8
 * Fixed that partials would be broken when using text.plain.erb as the extension #10130 [java]
4 9
 
5 10
 * Update README to use new smtp settings configuration API. Closes #10060 [psq]
35  actionmailer/lib/action_mailer/base.rb
@@ -298,11 +298,6 @@ class Base
298 298
     # This defaults to the value for the +default_implicit_parts_order+.
299 299
     adv_attr_accessor :implicit_parts_order
300 300
     
301  
-    # Override the mailer name, which defaults to an inflected version of the
302  
-    # mailer's class name. If you want to use a template in a non-standard
303  
-    # location, you can use this to specify that location.
304  
-    adv_attr_accessor :mailer_name
305  
-    
306 301
     # Defaults to "1.0", but may be explicitly given if needed.
307 302
     adv_attr_accessor :mime_version
308 303
     
@@ -322,10 +317,35 @@ class Base
322 317
     # have multiple mailer methods share the same template.
323 318
     adv_attr_accessor :template
324 319
 
  320
+    # Override the mailer name, which defaults to an inflected version of the
  321
+    # mailer's class name. If you want to use a template in a non-standard
  322
+    # location, you can use this to specify that location.
  323
+    def mailer_name(value = nil)
  324
+      if value
  325
+        self.mailer_name = value
  326
+      else
  327
+        self.class.mailer_name
  328
+      end
  329
+    end
  330
+    
  331
+    def mailer_name=(value)
  332
+      self.class.mailer_name = value
  333
+    end
  334
+
325 335
     # The mail object instance referenced by this mailer.
326 336
     attr_reader :mail
327 337
 
328 338
     class << self
  339
+      attr_writer :mailer_name
  340
+
  341
+      def mailer_name
  342
+        @mailer_name ||= name.underscore
  343
+      end
  344
+
  345
+      # for ActionView compatibility
  346
+      alias_method :controller_name, :mailer_name
  347
+      alias_method :controller_path, :mailer_name
  348
+
329 349
       def method_missing(method_symbol, *parameters)#:nodoc:
330 350
         case method_symbol.id2name
331 351
           when /^create_([_a-z]\w*)/  then new($1, *parameters).mail
@@ -476,6 +496,9 @@ def render_message(method_name, body)
476 496
 
477 497
       def render(opts)
478 498
         body = opts.delete(:body)
  499
+        if opts[:file] && opts[:file] !~ /\//
  500
+          opts[:file] = "#{mailer_name}/#{opts[:file]}"
  501
+        end
479 502
         initialize_template_class(body).render(opts)
480 503
       end
481 504
 
@@ -484,7 +507,7 @@ def template_path
484 507
       end
485 508
 
486 509
       def initialize_template_class(assigns)
487  
-        ActionView::Base.new(template_path, assigns, self)
  510
+        ActionView::Base.new([template_root], assigns, self)
488 511
       end
489 512
 
490 513
       def sort_parts(parts, order = [])
0  ...t/fixtures/test_mailer/subtemplate.text.plain.erb → .../fixtures/test_mailer/_subtemplate.text.plain.erb
File renamed without changes
2  actionmailer/test/fixtures/test_mailer/included_subtemplate.text.plain.erb
... ...
@@ -1 +1 @@
1  
-Hey Ho, <%= render "subtemplate" %>
  1
+Hey Ho, <%= render :partial => "subtemplate" %>
13  actionmailer/test/mail_render_test.rb
@@ -26,6 +26,13 @@ def included_subtemplate(recipient)
26 26
     subject    "Including another template in the one being rendered"
27 27
     from       "tester@example.com"
28 28
   end
  29
+  
  30
+  def included_old_subtemplate(recipient)
  31
+    recipients recipient
  32
+    subject    "Including another template in the one being rendered"
  33
+    from       "tester@example.com"
  34
+    body       render(:inline => "Hello, <%= render \"subtemplate\" %>", :body => { :world => "Earth" })
  35
+  end
29 36
 
30 37
   def initialize_defaults(method_name)
31 38
     super
@@ -81,6 +88,12 @@ def test_included_subtemplate
81 88
     mail = RenderMailer.deliver_included_subtemplate(@recipient)
82 89
     assert_equal "Hey Ho, let's go!", mail.body.strip
83 90
   end
  91
+  
  92
+  def test_deprecated_old_subtemplate
  93
+    assert_raises ActionView::ActionViewError do
  94
+      RenderMailer.deliver_included_old_subtemplate(@recipient)
  95
+    end
  96
+  end
84 97
 end
85 98
 
86 99
 class FirstSecondHelperTest < Test::Unit::TestCase

0 notes on commit bd5ed65

Please sign in to comment.
Something went wrong with that request. Please try again.