Skip to content
This repository
Browse code

Fix for ActionMailer::Base.method_missing so that it raises NoMethodE…

…rror when no method is found [#1330 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit a62e9e90d8f47a643c9355f782ab4891fa8fefaa 1 parent 78a1839
Joel Chippindale authored josh committed
14  actionmailer/lib/action_mailer/base.rb
@@ -386,12 +386,14 @@ def respond_to?(method_symbol, include_private = false) #:nodoc:
386 386
       end
387 387
 
388 388
       def method_missing(method_symbol, *parameters) #:nodoc:
389  
-        match = matches_dynamic_method?(method_symbol)
390  
-        case match[1]
391  
-          when 'create'  then new(match[2], *parameters).mail
392  
-          when 'deliver' then new(match[2], *parameters).deliver!
393  
-          when 'new'     then nil
394  
-          else super
  389
+        if match = matches_dynamic_method?(method_symbol)
  390
+          case match[1]
  391
+            when 'create'  then new(match[2], *parameters).mail
  392
+            when 'deliver' then new(match[2], *parameters).deliver!
  393
+            when 'new'     then nil
  394
+          end
  395
+        else
  396
+          super
395 397
         end
396 398
       end
397 399
 
8  actionmailer/test/mail_service_test.rb
@@ -1045,4 +1045,12 @@ def test_should_not_respond_to_create_with_template_suffix_if_it_begins_with_a_d
1045 1045
   def test_should_not_respond_to_deliver_with_template_suffix_if_it_begins_with_a_digit
1046 1046
     assert !RespondToMailer.respond_to?(:deliver_1_template)
1047 1047
   end
  1048
+
  1049
+  def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
  1050
+    error = assert_raises NoMethodError do
  1051
+      RespondToMailer.not_a_method
  1052
+    end
  1053
+
  1054
+    assert_match /undefined method.*not_a_method/, error.message
  1055
+  end
1048 1056
 end

0 notes on commit a62e9e9

Please sign in to comment.
Something went wrong with that request. Please try again.