This project is archived and is in readonly mode.
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
-
Clemens Kofler July 25th, 2008 @ 02:17 AM
- Tag changed from mailer, patch to actionmailer, bug, patch, tested, tests
+1. Plus we should probably investigate if the same happens as well for other cases where method_missing is used.
-
Luke Redpath August 20th, 2008 @ 09:31 AM
+1 - if it quacks like a duck, it should know that it can quack like a duck.
-
Chris Roos August 20th, 2008 @ 10:01 AM
- The current implementation generates a lot of unnecessary noise when you disable the stubbing of non existent methods in Mocha.
-
Repository August 29th, 2008 @ 09:10 PM
- State changed from new to resolved
(from [3cf773b187e803e16b8237e5923fa4c1139cde8a]) ActionMailer should respond_to? to methods handled by method_missing [#700 state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
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
Attachments
Tags
Referenced by
- 700 ActionMailer::Base should respond to methods handled by method_missing (from [3cf773b187e803e16b8237e5923fa4c1139cde8a]) ActionM...