Hello,
  I have discovered some issues with Action Mailer. To reproduce them:

Create multiple mailers with the same action say, (FirstMailer and
SecondMailer) with action `share'.

Now, the way the action mailer code is currently written,
'compile_and_render_template' function will assign the same function to the
action in both the mailers. To test, this make both the FirstMailer and then
SecondMailer send email. 'compile_and_render_template' will now store the
rendered value of the template for SecondMailer mailer.
And while sending the mails using FirstMailer, always the SecondMailer
template will be used.

I have added a patch and test which will fix this. 

Without applying the patch to base.rb, if the patch to test files is applied,
and the tests are run, it will cause an assertion failure. 

<"first mail"> expected but was <"second mail">. 

Showing the scenario which I discussed above.

If there are any issues with the patch, I will do my best to help. I would
like this patch or something else which fixes this problem as soon as
possible. 

It might also fix ticket - http://dev.rubyonrails.org/ticket/5466

I have also added this patch as a ticket. 

http://dev.rubyonrails.org/ticket/5520

Thanks and regards.
P.S.- the diffs are against edge rails 

Index: lib/action_mailer/base.rb
===================================================================
--- lib/action_mailer/base.rb	(revision 4495)
+++ lib/action_mailer/base.rb	(working copy)
@@ -353,7 +353,7 @@
             content_type = md.captures[1].gsub('.', '/')
             @parts << Part.new(:content_type => content_type,
               :disposition => "inline", :charset => charset,
-              :body => render_message(template_name, @body))
+              :body => render_message("#{mailer_name}/#{template_name}", @body))
           end
           unless @parts.empty?
             @content_type = "multipart/alternative"
@@ -367,7 +367,7 @@
         # it.
         template_exists = @parts.empty?
         template_exists ||= Dir.glob("#{template_path}/[EMAIL PROTECTED]").any? { |i| File.basename(i).split(".").length == 2 }
-        @body = render_message(@template, @body) if template_exists
+        @body = render_message("#{mailer_name}/[EMAIL PROTECTED]", @body) if template_exists
 
         # Finally, if there are other message parts and a textual body exists,
         # we shift it onto the front of the parts and set the body to nil (so
@@ -432,7 +432,7 @@
       end
 
       def initialize_template_class(assigns)
-        ActionView::Base.new(template_path, assigns, self)
+        ActionView::Base.new(template_root, assigns, self)
       end
 
       def sort_parts(parts, order = [])
Index: test/mail_service_test.rb
===================================================================
--- test/mail_service_test.rb	(revision 4495)
+++ test/mail_service_test.rb	(working copy)
@@ -32,7 +32,7 @@
       :body => "not really a jpeg, we're only testing, after all"
   end
 
-  def template_path
+  def template_root
     "#{File.dirname(__FILE__)}/fixtures/path.with.dots"
   end
 end
Index: test/mail_render_test.rb
===================================================================
--- test/mail_render_test.rb	(revision 4495)
+++ test/mail_render_test.rb	(working copy)
@@ -15,7 +15,7 @@
     recipients recipient
     subject    "using helpers"
     from       "[EMAIL PROTECTED]"
-    body       render(:file => "signed_up", :body => { :recipient => recipient })
+    body       render(:file => "#{mailer_name}/signed_up", :body => { :recipient => recipient })
   end
 
   def initialize_defaults(method_name)
@@ -24,6 +24,22 @@
   end
 end
 
+class FirstMailer < ActionMailer::Base
+  def share(recipient)
+    recipients recipient
+    subject    "using helpers"
+    from       "[EMAIL PROTECTED]"
+  end
+end
+
+class SecondMailer < ActionMailer::Base
+  def share(recipient)
+    recipients recipient
+    subject    "using helpers"
+    from       "[EMAIL PROTECTED]"
+  end
+end
+
 RenderMailer.template_root = File.dirname(__FILE__) + "/fixtures"
 
 class RenderHelperTest < Test::Unit::TestCase
@@ -46,3 +62,23 @@
   end
 end
 
+class FirstSecondHelperTest < Test::Unit::TestCase
+  def setup
+    ActionMailer::Base.delivery_method = :test
+    ActionMailer::Base.perform_deliveries = true
+    ActionMailer::Base.deliveries = []
+
+    @recipient = '[EMAIL PROTECTED]'
+  end
+
+  def test_ordering
+    mail = FirstMailer.create_share(@recipient)
+    assert_equal "first mail", mail.body.strip
+    mail = SecondMailer.create_share(@recipient)
+    assert_equal "second mail", mail.body.strip
+    mail = FirstMailer.create_share(@recipient)
+    assert_equal "first mail", mail.body.strip
+    mail = SecondMailer.create_share(@recipient)
+    assert_equal "second mail", mail.body.strip
+  end
+end
Index: first_mailer/share.rhtml
===================================================================
--- first_mailer/share.rhtml	(revision 0)
+++ first_mailer/share.rhtml	(revision 0)
@@ -0,0 +1 @@
+first mail
Index: second_mailer/share.rhtml
===================================================================
--- second_mailer/share.rhtml	(revision 0)
+++ second_mailer/share.rhtml	(revision 0)
@@ -0,0 +1 @@
+second mail
Index: path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.rhtml
===================================================================
--- path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.rhtml	(revision 0)
+++ path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.rhtml	(revision 0)
@@ -0,0 +1 @@
+Have a lovely picture, from me. Enjoy!
\ No newline at end of file
Index: path.with.dots/multipart_with_template_path_with_dots.rhtml
===================================================================
--- path.with.dots/multipart_with_template_path_with_dots.rhtml	(revision 4495)
+++ path.with.dots/multipart_with_template_path_with_dots.rhtml	(working copy)
@@ -1 +0,0 @@
-Have a lovely picture, from me. Enjoy!
\ No newline at end of file
-- 
Surendra Singhi
http://ssinghi.kreeti.com, http://www.kreeti.com
Read my blog at: http://cuttingtheredtape.blogspot.com/
,----
| "All animals are equal, but some animals are more equal than others."
|     -- Orwell, Animal Farm, 1945
`----
_______________________________________________
Rails-core mailing list
Rails-core@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-core

Reply via email to