This project is archived and is in readonly mode.

#700 ✓resolved
James Mead

ActionMailer::Base should respond to methods handled by method_missing

Reported by James Mead | July 25th, 2008 @ 01:07 AM | in 2.x

ActionMailer::Base uses method_missing to handle dynamic create & deliver methods, but does not alter respond_to? to include the handled methods. So for example:

TopicMailer.deliver_activation_email # => although this works
TopicMailer.respond_to?(:deliver_activation_email) # => this returns false

It's my understanding that if you implement method_missing on a class to handle extra methods, you should add a corresponding implementation of respond_to? which recognizes the methods that method_missing will handle. Dan Manges has a nice explanation on his blog. If this were fixed, the above example becomes:

TopicMailer.deliver_activation_email # => this still works
TopicMailer.respond_to?(:deliver_activation_email) # => this returns true

I have a practical reason for wanting this fixed. I've added functionality to Mocha which allows you to get warnings or errors when stubbing non-existent methods. The problem is that when running in a Rails project, false negatives are produced when you are legitimately stubbing ActionMailer create/deliver methods. I think this functionality could be really useful in catching incorrectly stubbed methods.

The attached patch fixes this problem. It includes tests which fail against the current implementation and tests that check that original behaviour is preserved.

This ticket corresponds to a similar patch applied to ActiveRecord::Base.

I wonder whether the method_missing interception of the "new" method is really necessary - there is only one (seemingly insignificant) test failure if this is removed. Also it would be good if method_missing and thus respond_to? checked whether the requested template existed - in a similar manner to ActiveRecord::Base checking whether a specific dynamic finder exists depending on attributes.

Comments and changes to this ticket

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>

Attachments

Referenced by

Pages