Fixed method_missing for ActionMailer so it no longer matches methods where deliver or create are not a suffix [#1318 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
Joel Chippindale 2008-11-11 09:45:53 -06:00 committed by Joshua Peek
parent a62e9e90d8
commit c65075feb6
2 changed files with 6 additions and 1 deletions

View File

@ -391,6 +391,7 @@ module ActionMailer #:nodoc:
when 'create' then new(match[2], *parameters).mail when 'create' then new(match[2], *parameters).mail
when 'deliver' then new(match[2], *parameters).deliver! when 'deliver' then new(match[2], *parameters).deliver!
when 'new' then nil when 'new' then nil
else super
end end
else else
super super
@ -442,7 +443,7 @@ module ActionMailer #:nodoc:
private private
def matches_dynamic_method?(method_name) #:nodoc: def matches_dynamic_method?(method_name) #:nodoc:
method_name = method_name.to_s method_name = method_name.to_s
/(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name) /^(create|deliver)_([_a-z]\w*)/.match(method_name) || /^(new)$/.match(method_name)
end end
end end

View File

@ -1046,6 +1046,10 @@ class RespondToTest < Test::Unit::TestCase
assert !RespondToMailer.respond_to?(:deliver_1_template) assert !RespondToMailer.respond_to?(:deliver_1_template)
end end
def test_should_not_respond_to_method_where_deliver_is_not_a_suffix
assert !RespondToMailer.respond_to?(:foo_deliver_template)
end
def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method def test_should_still_raise_exception_with_expected_message_when_calling_an_undefined_method
error = assert_raises NoMethodError do error = assert_raises NoMethodError do
RespondToMailer.not_a_method RespondToMailer.not_a_method