Glad You're Ready. Let's Get Started!

Let us know how we can contact you.

Thank you!

We'll respond shortly.

Standup 06/18/2010: ActionMailer day

Ask for Help

“How can I turn off logging of email attachments in ActionMailer?”

You’re not the only person ever to ask that.

Actionmailer’s deliver method looks like this:

     # File vendor/rails/actionmailer/lib/action_mailer/base.rb, line 473
473:     def deliver!(mail = @mail)
474:       raise "no mail object available for delivery!" unless mail
475:       unless logger.nil?
476:  "Sent mail to #{Array(recipients).join(', ')}"
477:         logger.debug "n#{mail.encoded}"
478:       end
480:       begin
481:         __send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries
482:       rescue Exception => e  # Net::SMTP errors or sendmail pipe errors
483:         raise e if raise_delivery_errors
484:       end
486:       return mail
487:     end

And the actual delivery methods look like this:

     # File vendor/rails/actionmailer/lib/action_mailer/base.rb, line 594
594:       def perform_delivery_smtp(mail)
595:         destinations = mail.destinations
596:         mail.ready_to_send
597:         sender = mail['return-path'] || mail.from
599:         Net::SMTP.start(smtp_settings[:address], smtp_settings[:port], smtp_settings[:domain],
600:             smtp_settings[:user_name], smtp_settings[:password], smtp_settings[:authentication]) do |smtp|
601:           smtp.sendmail(mail.encoded, sender, destinations)
602:         end
603:       end

If you compare lines 477 and 601, you will see that they both hook directly into the “encoded” method on the Tmail object. If you want to fix this, you’re going to have to patch (or monkeypathch) ActionMailer

“Why is Selenium running tests before Jelly has finished loading?”

The answer to this was that Webrat has a waiting period, and if you have a long load time you need to increase it.

try this to fix your selenium timeout problem (in your selenium_spec_helper.rb or equivalent):

Webrat.configure do |config|
  config.mode = :selenium
  config.selenium_browser_startup_timeout = 60

Interesting Things

  • RVM hooks into Textmate.
    You can set up Textmate to run tests using an RVM Ruby. See this, for example.
  • There are WWDC videos on iTunes if you have a Developer account.
  • Garbage Collection: If you are using REE you need to pay attention to your garbage collection strategies. Even at low load levels it can make a difference in request time.
  • Syslog-ng templates: If you have multiple servers, and you are using syslog-ng and Splnuk (you should be) you can format your syslog-ng log lines using templates.
  • mail_safe: This is a gem that whitelists domains so all outbound email instead goes to you. Just install it and then
    config.gem mail_safe

    Of course, if you do this in production your emails won’t work. Use it wisely.

  1. Tom Cocca says:

    Can you elaborate on your garbage collection strategies for REE? I was under the impression that the whole purpose of using REE was that Phusion re-wrote the garbage collection and improved it over the traditional MRI Ruby.

    ~ Tom

  2. David Stevenson says:

    Tom –

    I made that comment on Friday. Our experience was that installing rubyEE and using the Twitter GC settings (from EE documentation) improved the speed of our rspec runs by a factor of 2! Cucumbers with rails integration runner as well. The only danger here might be running your tests in REE but your production code in MRI. You should at least have CI running the same version as production.


Post a Comment

Your Information (Name required. Email address will not be displayed with comment.)

* Copy This Password *

* Type Or Paste Password Here *