This project is archived and is in readonly mode.
Rails 2.3.2 breaks implicit multipart actionmailer tests
-
James Adam
FYI - I'm also seeing this behaviour.
-
Chris Williams
me too
-
thedarkone
Can't reproduce, what exactly do I need to do to get an error?
-
Tom
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.
-
thedarkone
A 1 mailer example app on github would be awesome.
-
Philippe Huibonhoa
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
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
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
I'm not sure
ActionMailershould depend onRAILS_ROOTconstant to be defined. I would also like to note that all view template lookup machinery is dependent onpwdmaking sense and not being a random dir.If you are having issues with
pwdmy suggestion would be to absolutizeActionViewandActionMailerview_pathswith something like this:ActionView::Base.view_paths = ActionView::Base.view_paths.map{|path| File.expand_path(path, Rails.root)} // same for ActionMailer -
Logan Bowers
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
Fair enough.
PS: the paths are expanded because Rails initializer for some reason goes ahead and pre-expands them on its own.
ActionViewmachinery 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 theActionMailertests), also any user definedview_paths, per controllerview_paths, per requestview_pathsare not auto-expanded. Expandedview_pathsare an exception not the rule. -
thedarkone
PS2: the bug doesn't have that much to do with
ActionMailer, but stems from the fact thatActionView::Pathsuspects, that an initializer had its way with it and is now prudently trying to hide the aforementioned fact inPath#to_s. -
Bruno Michel
+1 for the patch by thedarkone. It fixes my problem with multipart emails (under fastcgi).
-
Philippe Huibonhoa
+1 for thedarkone's patch; it fixed my mailer tests
-
Menno van der Sman
- 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
My ActionMailer was also broken after upgrading to 2.3.2. thedarkone's patch saved the day and fixed it. +1
-
Brendon
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
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...
-
Randy Puro
+1 for the patch by thedarkone - fixed our deployment.
-
Steven
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
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
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 endAlso 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
- Assigned user set to josh
- Milestone changed from 2.x to 2.3.4
-
josh
- Assigned user changed from josh to Yehuda Katz (wycats)
-
Evgeniy Dolzhenko
+1 to the aforementioned patch, was breaking the email sending from cron tasks
-
CDD Developers
+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
swallowed my square brackets, should have been "#{<path element 1>}/#{<path element 2>}", but you get the point.
-
José Valim
- 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
Should it be rebase on top of master or 2-3-stable, or both?
Cheers
-
José Valim
On top of 2-3-stable. In master this works for sure.
-
Rodrigo Kochenburger
Which patch did you use? Both breaks?
-
José Valim
I used the latest one:
https://rails.lighthouseapp.com/projects/8994/tickets/2263/a/217365...
-
Rodrigo Kochenburger
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
- 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...
