This project is archived and is in readonly mode.
Bug(?) - ActionMailer responds_to? failing to return true/false bug
Reported by PommyTom | April 24th, 2009 @ 10:00 AM | in 3.x
Hi,
Code base - Rails 2.3.2
When testing the action mailer object for an existing and non-existant method the object returned is a MatchData class. I've played around in actionmailer/lib/action_mailer/base.rb but haven't determined exactly why this is happening yet.
To replicate this issue:
rails test_mail
cd test_mail
ruby script/generate mailer Mail
Add the following method to app/models/mail.rb: def self.test_method puts "do nothing" end
def test_email puts "this is accessed by Mail.deliver_test_email!" end
ruby script/console
Loading development environment (Rails 2.3.2)
Mail.respond_to?(:something)
=> false
Mail.respond_to?(:deliver_anything)
=> #<MatchData:0x24509f0>
Mail.respond_to?(:create_anything)
=> #<MatchData:0x244e664>
Mail.respond_to?(:test_method)
=> true
Mail.respond_to?(:test_email)
=> false
Mail.respond_to?(:deliver_test_email)
=> #<MatchData:0x2450680>
Mail.respond_to?(:deliver_test_email!)
=> #<MatchData:0x244e1b4>
The workaround I'm using at the moment is testing the method name (without deliver/create) is present in the instance_methods:
Mail.instance_method.include?(:test_email)
But i don't think this is the way i should be testing the existance of a dynamic method on the action mailer object.
Please let me know if i'm looking at this all wrong. Any other info required i'd be happy to help.
Best regards,
Tom
Comments and changes to this ticket
-
Frederick Cheung May 7th, 2009 @ 11:25 PM
- Tag changed from 2.3.2, actionmailer, base, rails, respond_to to 2.3.2, actionmailer, base, rails, respond_to
Does it really matter? ruby will happily consider anything other than nil/false as true for the purposes of an if statement and so on.
-
PommyTom May 14th, 2009 @ 02:25 AM
Hi Frederick,
Yeah, that would be fine normally, as it responds with true just for having a value. But the problem with this instance as described above, it is returning a object for any values that start with the dynamic method starts (such as deliver... or create...) so with a matchdata being returned it will always return true even though the method doesn't actually exist (matchdata also returned when the method does exist such as deliver_test_email in the example above).
Any other info you require, please let me know.
Best regards,
Tom
-
Frederick Cheung May 15th, 2009 @ 01:43 PM
Ah, I'm with you now, it's not actually checking whether foo exists when handling respond_to 'deliver_foo'
-
Santiago Pastorino February 2nd, 2011 @ 05:02 PM
- State changed from new to open
- Tag changed from 2.3.2, actionmailer, base, rails, respond_to to 232, actionmailer, base, rails, respond_to
- Importance changed from to
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
Santiago Pastorino February 2nd, 2011 @ 05:02 PM
- State changed from open to stale
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
Tags
Referenced by
- 2556 ActionMailer responds_to? failing to return true/false bug duplicate of #2557