This project is archived and is in readonly mode.
Fix for matches_dynamic_method? on ActionMailer
-
Joel Chippindale
The attached patch fixes this and makes Action::Mailer.method_missing just catch methods which begin with create and deliver
-
Joel Chippindale
- Title changed from [PATCH]: Make ActionMailer::Base.method_missing more precise to Make ActionMailer::Base.method_missing more precise
-
Tom Lea
Well spotted! I have a couple of enhancements to the patch that could be made.
match = matches_dynamic_method?(method_symbol)looks clearly broken as of 3cf773b. This should be fixed separately, possibly in a separate commit, with another failing testcase (ex1 is a fairly ugly way of doing this).- Commit notes should be referring to Prefix not Suffix ;)
- Having two else conditions with calls to super in a row does not scan well. How about using (ex2) at the top? It also gets rid of a layer of nesting, which is nice.
ex1:
def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method begin RespondToMailer.not_a_method fail("Expected a NoMethodError.") rescue NoMethodError => e assert_match(/undefined method.*not_a_method/, e.message) rescue Exception => e fail("Expected a NoMethodError, got #{e.class}.") end endex2:
return super unless match = matches_dynamic_method?(method_symbol) -
Joel Chippindale
- Title changed from Make ActionMailer::Base.method_missing more precise to Fix for matches_dynamic_method? on ActionMailer
Thanks for the suggestions Tom.
- As you suggested it seems like a good idea to split these two issues.
I have created a separate ticket #1330 Fix for ActionMailer::Base.method_missing so that it raises NoMethodError whe... for the problem with method_missing not raising an exception correctly when an undefined method is called and included a test case for this (based on ex1 above).
I removed the first call to super in this (because the line of code is never reached) but did not implement ex2 (above) because I think it is clearer to have an if/else statement in this case.
- Oops. Fixed
A new patch is attached with just the fix for matches_dynamic_method in it
-
James Mead
+1 Joel, Tom - Thanks for fixing my original commit and sorry for introducing the bug. Cheers, James.
-
Repository
- State changed from new to resolved
(from [c65075feb6c4ce15582bc08411e6698d782249a7]) Fixed method_missing for ActionMailer so it no longer matches methods where deliver or create are not a suffix [#1318 Fix for matches_dynamic_method? on ActionMailer state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
