Skip to content
This repository
Browse code

Handle some TODOs and deprecations.

  • Loading branch information...
commit 99f960a3d73b62a957988bbee0906264f35afc2e 1 parent 0d931fe
authored January 24, 2010
2  actionmailer/lib/action_mailer/adv_attr_accessor.rb
... ...
@@ -1,8 +1,6 @@
1 1
 module ActionMailer
2 2
   module AdvAttrAccessor #:nodoc:
3 3
     def adv_attr_accessor(*names)
4  
-      
5  
-      # TODO: ActiveSupport::Deprecation.warn()
6 4
       names.each do |name|
7 5
         ivar = "@#{name}"
8 6
 
39  actionmailer/lib/action_mailer/base.rb
@@ -302,7 +302,6 @@ def mailer_name
302 302
         @mailer_name ||= name.underscore
303 303
       end
304 304
       attr_writer :mailer_name
305  
-
306 305
       alias :controller_path :mailer_name
307 306
 
308 307
       # Receives a raw email, parses it into an email object, decodes it,
@@ -324,23 +323,21 @@ def receive(raw_mail)
324 323
         end
325 324
       end
326 325
 
327  
-      def template_root
328  
-        self.view_paths && self.view_paths.first
329  
-      end
330  
-
331  
-      # Should template root overwrite the whole view_paths?
332  
-      def template_root=(root)
333  
-        self.view_paths = ActionView::Base.process_view_paths(root)
334  
-      end
335  
-
336 326
       # TODO The delivery should happen inside the instrument block
337 327
       def delivered_email(mail)
338  
-        ActiveSupport::Notifications.instrument("action_mailer.deliver", :mailer => self.name) do |payload|
  328
+        ActiveSupport::Notifications.instrument("action_mailer.deliver") do |payload|
339 329
           self.set_payload_for_mail(payload, mail)
340 330
         end
341 331
       end
342 332
 
  333
+      def respond_to?(method, *args) #:nodoc:
  334
+        super || action_methods.include?(method.to_s)
  335
+      end
  336
+
  337
+    protected
  338
+
343 339
       def set_payload_for_mail(payload, mail) #:nodoc:
  340
+        payload[:mailer]     = self.name
344 341
         payload[:message_id] = mail.message_id
345 342
         payload[:subject]    = mail.subject
346 343
         payload[:to]         = mail.to
@@ -351,13 +348,7 @@ def set_payload_for_mail(payload, mail) #:nodoc:
351 348
         payload[:mail]       = mail.encoded
352 349
       end
353 350
 
354  
-      def respond_to?(method, *args)
355  
-        super || action_methods.include?(method.to_s)
356  
-      end
357  
-
358  
-    protected
359  
-
360  
-      def method_missing(method, *args)
  351
+      def method_missing(method, *args) #:nodoc:
361 352
         if action_methods.include?(method.to_s)
362 353
           new(method, *args).message
363 354
         else
@@ -459,7 +450,7 @@ def collect_responses_and_sort_order(headers) #:nodoc:
459 450
           :content_type => self.class.default_content_type.dup
460 451
         }
461 452
       else
462  
-        self.class.template_root.find_all(action_name, {}, self.class.mailer_name).each do |template|
  453
+        each_template do |template|
463 454
           responses << {
464 455
             :body => render_to_body(:_template => template),
465 456
             :content_type => template.mime_type.to_s
@@ -470,6 +461,16 @@ def collect_responses_and_sort_order(headers) #:nodoc:
470 461
       [responses, sort_order]
471 462
     end
472 463
 
  464
+    def each_template(&block) #:nodoc:
  465
+      self.class.view_paths.each do |load_paths|
  466
+        templates = load_paths.find_all(action_name, {}, self.class.mailer_name)
  467
+        unless templates.empty?
  468
+          templates.each(&block)
  469
+          return
  470
+        end
  471
+      end
  472
+    end
  473
+
473 474
     def create_parts_from_responses(m, responses, charset) #:nodoc:
474 475
       if responses.size == 1 && !m.has_attachments?
475 476
         m.body = responses[0][:body]
21  actionmailer/lib/action_mailer/deprecated_api.rb
@@ -25,11 +25,20 @@ def deliver(mail, show_warning=true)
25 25
         mail
26 26
       end
27 27
 
28  
-      def respond_to?(method_symbol, include_private = false) #:nodoc:
  28
+      def template_root
  29
+        self.view_paths && self.view_paths.first
  30
+      end
  31
+
  32
+      def template_root=(root)
  33
+        ActiveSupport::Deprecation.warn "template_root= is deprecated, use view_paths.unshift instead", caller[0,2]
  34
+        self.view_paths = ActionView::Base.process_view_paths(root)
  35
+      end
  36
+
  37
+      def respond_to?(method_symbol, include_private = false)
29 38
         matches_dynamic_method?(method_symbol) || super
30 39
       end
31 40
 
32  
-      def method_missing(method_symbol, *parameters) #:nodoc:
  41
+      def method_missing(method_symbol, *parameters)
33 42
         if match = matches_dynamic_method?(method_symbol)
34 43
           case match[1]
35 44
             when 'create'
@@ -49,7 +58,7 @@ def method_missing(method_symbol, *parameters) #:nodoc:
49 58
 
50 59
     private
51 60
 
52  
-      def matches_dynamic_method?(method_name) #:nodoc:
  61
+      def matches_dynamic_method?(method_name)
53 62
         method_name = method_name.to_s
54 63
         /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
55 64
       end
@@ -70,10 +79,8 @@ def render(*args)
70 79
       if options[:body]
71 80
         ActiveSupport::Deprecation.warn(':body in render deprecated. Please use instance ' <<
72 81
                                         'variables as assigns instead', caller[0,1])
73  
-
74 82
         body options.delete(:body)
75 83
       end
76  
-
77 84
       super
78 85
     end
79 86
 
@@ -93,13 +100,11 @@ def render_message(*args)
93 100
 
94 101
   private
95 102
     
96  
-
97  
-    def create_parts #:nodoc:
  103
+    def create_parts
98 104
       if @body.is_a?(Hash) && !@body.empty?
99 105
         ActiveSupport::Deprecation.warn "Giving a hash to body is deprecated, please use instance variables instead", caller[0,2]
100 106
         @body.each { |k, v| instance_variable_set(:"@#{k}", v) }
101 107
       end
102  
-
103 108
       super
104 109
     end
105 110
 
16  actionmailer/lib/action_mailer/old_api.rb
... ...
@@ -1,5 +1,5 @@
1 1
 module ActionMailer
2  
-  module OldApi
  2
+  module OldApi #:nodoc:
3 3
     extend ActiveSupport::Concern
4 4
 
5 5
     included do
@@ -144,7 +144,7 @@ def normalize_file_hash(params)
144 144
         :content_disposition => content_disposition }.merge(params)
145 145
     end
146 146
     
147  
-    def create_mail #:nodoc:
  147
+    def create_mail 
148 148
       m = @_message
149 149
 
150 150
       quote_fields!({:subject => subject, :to => recipients, :from => from,
@@ -184,7 +184,7 @@ def create_mail #:nodoc:
184 184
     # Set up the default values for the various instance variables of this
185 185
     # mailer. Subclasses may override this method to provide different
186 186
     # defaults.
187  
-    def initialize_defaults(method_name) #:nodoc:
  187
+    def initialize_defaults(method_name) 
188 188
       @charset              ||= self.class.default_charset.dup
189 189
       @content_type         ||= self.class.default_content_type.dup
190 190
       @implicit_parts_order ||= self.class.default_implicit_parts_order.dup
@@ -200,7 +200,7 @@ def initialize_defaults(method_name) #:nodoc:
200 200
       @body ||= {}
201 201
     end
202 202
 
203  
-    def create_parts #:nodoc:
  203
+    def create_parts 
204 204
       if String === @body
205 205
         self.response_body = @body
206 206
       end
@@ -208,7 +208,7 @@ def create_parts #:nodoc:
208 208
       if String === response_body
209 209
         @parts.unshift create_inline_part(response_body)
210 210
       else
211  
-        self.class.template_root.find_all(@template, {}, @mailer_name).each do |template|
  211
+        self.class.view_paths.first.find_all(@template, {}, @mailer_name).each do |template|
212 212
           @parts << create_inline_part(render_to_body(:_template => template), template.mime_type)
213 213
         end
214 214
 
@@ -222,7 +222,7 @@ def create_parts #:nodoc:
222 222
       end
223 223
     end
224 224
 
225  
-    def create_inline_part(body, mime_type=nil) #:nodoc:
  225
+    def create_inline_part(body, mime_type=nil) 
226 226
       ct = mime_type || "text/plain"
227 227
       main_type, sub_type = split_content_type(ct.to_s)
228 228
 
@@ -233,11 +233,11 @@ def create_inline_part(body, mime_type=nil) #:nodoc:
233 233
       )
234 234
     end
235 235
 
236  
-    def split_content_type(ct) #:nodoc:
  236
+    def split_content_type(ct) 
237 237
       ct.to_s.split("/")
238 238
     end
239 239
 
240  
-    def parse_content_type(defaults=nil) #:nodoc:
  240
+    def parse_content_type(defaults=nil) 
241 241
       if @content_type.blank?
242 242
         [ nil, {} ]
243 243
       else
1  actionmailer/lib/action_mailer/test_helper.rb
@@ -58,7 +58,6 @@ def assert_no_emails(&block)
58 58
   end
59 59
 end
60 60
 
61  
-# TODO: Deprecate this
62 61
 module Test
63 62
   module Unit
64 63
     class TestCase
6  actionmailer/test/mail_service_test.rb
@@ -1085,13 +1085,15 @@ def test_starttls_is_not_enabled
1085 1085
   end
1086 1086
 end
1087 1087
 
1088  
-class InheritableTemplateRootTest < Test::Unit::TestCase
  1088
+class InheritableTemplateRootTest < ActiveSupport::TestCase
1089 1089
   def test_attr
1090 1090
     expected = File.expand_path("#{File.dirname(__FILE__)}/fixtures/path.with.dots")
1091 1091
     assert_equal expected, FunkyPathMailer.template_root.to_s
1092 1092
 
1093 1093
     sub = Class.new(FunkyPathMailer)
1094  
-    sub.template_root = 'test/path'
  1094
+    assert_deprecated do
  1095
+      sub.template_root = 'test/path'
  1096
+    end
1095 1097
 
1096 1098
     assert_equal File.expand_path('test/path'), sub.template_root.to_s
1097 1099
     assert_equal expected, FunkyPathMailer.template_root.to_s

0 notes on commit 99f960a

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