This project is archived and is in readonly mode.
Rails 2.3.2 breaks implicit multipart actionmailer tests
Reported by Philippe Huibonhoa | March 17th, 2009 @ 05:34 AM | in 2.3.6
In rails 2.3.2 mailer tests break when you are using implicit multipart emails (ie your content type is part of the view file name: example.text.plain.erb) and you run the tests manually (ie not using rake)
As far as I can tell this is because ActionMailer:Base.template_path returns a relative path "app/views/xxx_mailer" where in the older versions of rails it would return "#{RAILS_ROOT}/app/views/xxx_mailer" because template_root now returns a relative path when you call to_s on it.
Comments and changes to this ticket
-
thedarkone March 25th, 2009 @ 10:51 PM
Can't reproduce, what exactly do I need to do to get an error?
-
Tom March 25th, 2009 @ 11:25 PM
I have the problem even in development mode. When ActionMailer attempts to deliver the email:
<ActionView::MissingTemplate: Missing template my_mailer/mailer_action.erb in view path app/views>
But the view is a multipart:
my_mailer/mailer_action.text.plain.erb my_mailer/mailer_action.text.html.erb
Everything worked fine before the upgrade to 2.3.2.
-
Philippe Huibonhoa March 26th, 2009 @ 02:10 AM
I think I figured out the problem. When you are only sending 1 format, the view file should be email_name.erb; you cannot have email_name.text.plain.erb unless you also have email_name.other_format.erb. In rails 2.2.2 it was happy to send email_name.text.plain.erb even if you didn't have another format you were sending.
The weird part now, though, is that when you do have multiple formats (email_name.text.plain.erb, email_name.text.html.erb), email.parts is empty. Shouldn't parts be populated with the html and plain text versions of the email? I attached a fresh project with a implicit multipart email, and a test on email.parts.size.
-
thedarkone March 26th, 2009 @ 03:28 AM
With Rails tag v2.3.2.1 in
vendor/rails
:$ cat ./test/unit/emailer_test.rb require 'test_helper' class EmailerTest < ActionMailer::TestCase def setup ActionMailer::Base.delivery_method = :test ActionMailer::Base.perform_deliveries = true ActionMailer::Base.deliveries = [] end def test_general email = Emailer.create_general() assert email.parts.size > 0 #should be an html and a plain text part end end $ ruby -Itest ./test/unit/emailer_test.rb Loaded suite ./test/unit/emailer_test Started . Finished in 0.173692 seconds. 1 tests, 1 assertions, 0 failures, 0 errors
-
Logan Bowers April 4th, 2009 @ 01:41 AM
The error occurs if Dir.pwd != RAILS_ROOT
This is the case for fastCGI scripts, and apparently tests. I'm seeing this behavior as well. Check line 468 of base.rb:
Dir.glob("#{template_path}/#{@template}.*").each do |path|
Should read:
Dir.glob("#{RAILS_ROOT}/#{template_path}/#{@template}.*").each do |path|
-
thedarkone April 4th, 2009 @ 06:22 PM
I'm not sure
ActionMailer
should depend onRAILS_ROOT
constant to be defined. I would also like to note that all view template lookup machinery is dependent onpwd
making sense and not being a random dir.If you are having issues with
pwd
my suggestion would be to absolutizeActionView
andActionMailer
view_paths
with something like this:ActionView::Base.view_paths = ActionView::Base.view_paths.map{|path| File.expand_path(path, Rails.root)} // same for ActionMailer
-
Logan Bowers April 6th, 2009 @ 07:20 PM
When serving rails via FastCGI, the pwd is RAILS_ROOT/public (always has been) and ActionView most definitely works (its paths are most definitely expanded). ActionMailer is broken in this respect. It does its own lookup to try to find the templates with embedded types and fails because it does the search relative to pwd. When it falls back to ActionView machinery, it finds the template just fine because AV does not run relative to pwd.
-
thedarkone April 6th, 2009 @ 08:54 PM
Fair enough.
PS: the paths are expanded because Rails initializer for some reason goes ahead and pre-expands them on its own.
ActionView
machinery makes no assumptions and works perfectly fine with relative template paths (in fact the whole Rails test suite runs on relative view paths, including all theActionMailer
tests), also any user definedview_paths
, per controllerview_paths
, per requestview_paths
are not auto-expanded. Expandedview_paths
are an exception not the rule. -
thedarkone April 6th, 2009 @ 09:15 PM
PS2: the bug doesn't have that much to do with
ActionMailer
, but stems from the fact thatActionView::Path
suspects, that an initializer had its way with it and is now prudently trying to hide the aforementioned fact inPath#to_s
. -
Bruno Michel April 22nd, 2009 @ 08:31 PM
+1 for the patch by thedarkone. It fixes my problem with multipart emails (under fastcgi).
-
Menno van der Sman May 8th, 2009 @ 03:25 PM
- Tag changed from 2.3.2, actionmailer, view_paths to 2.3.2, actionmailer, verified, view_paths
This problem also surfaces when running a mail-delivery task through script/runner ( in cron /absolute/path/to/app/script/runner -e production 'Mail.deliver_newsletter' for example ). Very nasty because our unit-tests did all pass, only to discover we were sending out plain-text in production.
Applied thedarkone's patch on v2.3.2.1 and fixed the problem, so +1.
-
Vidal Graupera May 18th, 2009 @ 09:00 PM
My ActionMailer was also broken after upgrading to 2.3.2. thedarkone's patch saved the day and fixed it. +1
-
Brendon May 19th, 2009 @ 02:31 AM
I'm seeing rails send my text.html.erb mail templates as plaintext, and no plaintext (text.plain.erb) templates added at all. Setting content_type "text/html" fixes it but the plaintext template still isn't attached.
This is in development, and since 2.3.2.
The patch above didn't seem to work for my situation.
-
Brian Armstrong May 31st, 2009 @ 08:05 PM
Thedarkone's patch seemed to fix some of the errors I was seeing, but not all.
I was still seeing some "missing template" errors in from my Cron jobs which use script/runner:
find_template': Missing template notifier/some_cron_email.erb in view path app/views (ActionView::MissingTemplate)
There was a "some_cron.email.plain.txt.erb" file present which it wasn't finding.
I was able to fix the remaining errors by cd'ing to my RAILS_ROOT before running script/runner
So instead of this in my Cron:
RAILS_ENV=production /home/admin/public_html/universitytutor.com/current/script/runner "Cron.some_cron_job"
I changed it to:
cd /home/admin/public_html/universitytutor.com/current; RAILS_ENV=production script/runner "Cron.some_cron_job"
And it works now!
Hope this helps...
-
Steven June 8th, 2009 @ 11:29 PM
Would it be possible to have this patch incorporated into the next release of Rails? I ran into this problem since my shared host account on railsplayground is running under FCGI. I suspect that lots of people who are using shared accounts may also be running under FCGI and experiencing this. Additionally, in a shared account situation, you don't have the permissions to apply patches so other than asking your hosting company to apply a patch (which they are nervous about & will affect everyone else on the box), don't have many other options.
If this fix won't be incorporated into Rails, would it be possible to monkey patch action_mailer to replace the methods being changed? If so, does anyone have any pointers on how you would do that in order to get it to happen in time? Would putting a file in lib/ work?
-
jbasdf June 27th, 2009 @ 12:48 AM
I'm trying to use the mailer in a Ruby on Rails 2.3.2 Engine and I'm experiencing a similar problem. All of my html emails show up as plain text.
-
Tom Lea July 9th, 2009 @ 04:40 PM
Also seeing this same issue, just patched it myself (almost the same patch as above).
Fixed it in production with the following hack:
raise "Not needed in rails 2.3.3 and above! You should delete this." unless Rails.version < "2.3.3" # Fix for relative paths when running tests. # https://rails.lighthouseapp.com/projects/8994/tickets/2263-rails-232-breaks-implicit-multipart-actionmailer-tests module ActionMailer class Base def template_path File.join(template_root, mailer_name) end end end
Also attached the patch I wrote for good measure, but just take it as a +1 for thedarkone's patch, it's functionally equivalent.
-
Michael Koziarski August 3rd, 2009 @ 06:10 AM
- Assigned user set to josh
- Milestone changed from 2.x to 2.3.4
-
josh August 3rd, 2009 @ 08:15 PM
- Assigned user changed from josh to Yehuda Katz (wycats)
-
Jeremy Kemper September 11th, 2009 @ 11:04 PM
- Milestone changed from 2.3.4 to 2.3.6
[milestone:id#50064 bulk edit command]
-
Evgeniy Dolzhenko January 4th, 2010 @ 02:32 PM
+1 to the aforementioned patch, was breaking the email sending from cron tasks
-
CDD Developers January 25th, 2010 @ 09:16 PM
+1 for Tom Lea's patch (using File.join is a little more elegant) - other examples of "#{}/#{}" should probably also be replaced by File.join in base.rb.
-
CDD Developers January 25th, 2010 @ 09:17 PM
swallowed my square brackets, should have been "#{<path element 1>}/#{<path element 2>}", but you get the point.
-
José Valim March 20th, 2010 @ 12:15 AM
- State changed from new to open
- Assigned user changed from Yehuda Katz (wycats) to José Valim
Tried to apply the patch, but the tests added fail. Can someone rebase it please?
-
Rodrigo Kochenburger March 20th, 2010 @ 06:17 PM
Should it be rebase on top of master or 2-3-stable, or both?
Cheers
-
Rodrigo Kochenburger March 22nd, 2010 @ 11:20 PM
The tests was breaking because the template_root path was being set to an relative path. Since we want it to work from outside the application path we need to set it as absolute.
In rails this already happens because it is set relative to Rails.root, which is an absolute path.
I'm adding a up-to-date patch.
-
Repository March 25th, 2010 @ 02:36 PM
- State changed from open to resolved
(from [0022fa309b6dd88d4019d1a94e6cd89866695349]) Set mailer template_root as absolute path [#2263 state:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/0022fa309b6dd88d4019d1a94e6cd8... -
csnk May 18th, 2011 @ 08:31 AM
- Importance changed from to High
We are the professional clothing manufacturer and clothing supplier, so we manufacture kinds of custom clothing manufacturer. welcome you to come to our china clothing manufacturer and clothing factory.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
- Betelgeuse
- Blake Carlson
- Bob Zoller
- Brendon
- CDD Developers
- Chad Woolley
- Chris Williams
- Dennis Martinez
- Ed Wagner
- Evgeniy Dolzhenko
- James Healy
- jbasdf
- jgutierrez (at inc21)
- Joren Six
- José Valim
- Marcin Michałowski
- Michael Klett
- Michael Koziarski
- Nadeem Bitar
- Philippe Huibonhoa
- Rodrigo Kochenburger
- Rust/OGAWA
- Santiago Pastorino
- Steven
- Tom
- Tom Lea
- Vidal Graupera
- Yehuda Katz (wycats)
- Zack Hubert
Attachments
Referenced by
- 2338 ActionMailer Mailer Views and Content Type Justin, I posted a similar patch in #2263 more than a mon...
- 2338 ActionMailer Mailer Views and Content Type Duplicate of #2263.
- 2263 Rails 2.3.2 breaks implicit multipart actionmailer tests https://rails.lighthouseapp.com/projects/8994/tickets/22...
- 2263 Rails 2.3.2 breaks implicit multipart actionmailer tests (from [0022fa309b6dd88d4019d1a94e6cd89866695349]) Set mai...