aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-30 13:28:14 -0500
committerRafael Mendonça França <rafaelmfranca@gmail.com>2017-01-30 13:28:14 -0500
commit735aa635c5c70928583eeabc8bf4c5e3bc278f8b (patch)
treea8fa5bb304597b586b05c0b12f46653551fd2398
parentbfc69e873dba88024e9a79bb13569e096fb39255 (diff)
downloadrails-735aa635c5c70928583eeabc8bf4c5e3bc278f8b.tar.gz
rails-735aa635c5c70928583eeabc8bf4c5e3bc278f8b.tar.bz2
rails-735aa635c5c70928583eeabc8bf4c5e3bc278f8b.zip
Implement respond_to_missing? in the Parameterized::Mailer class
-rw-r--r--actionmailer/lib/action_mailer/parameterized.rb17
-rw-r--r--actionmailer/test/parameterized_test.rb14
2 files changed, 25 insertions, 6 deletions
diff --git a/actionmailer/lib/action_mailer/parameterized.rb b/actionmailer/lib/action_mailer/parameterized.rb
index 7fa9da1724..73d98c198d 100644
--- a/actionmailer/lib/action_mailer/parameterized.rb
+++ b/actionmailer/lib/action_mailer/parameterized.rb
@@ -103,13 +103,18 @@ module ActionMailer
@mailer, @params = mailer, params
end
- def method_missing(method_name, *args)
- if @mailer.action_methods.include?(method_name.to_s)
- ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args)
- else
- super
+ private
+ def method_missing(method_name, *args)
+ if @mailer.action_methods.include?(method_name.to_s)
+ ActionMailer::Parameterized::MessageDelivery.new(@mailer, method_name, @params, *args)
+ else
+ super
+ end
+ end
+
+ def respond_to_missing?(method, include_all = false)
+ @mailer.respond_to?(method, include_all)
end
- end
end
class MessageDelivery < ActionMailer::MessageDelivery # :nodoc:
diff --git a/actionmailer/test/parameterized_test.rb b/actionmailer/test/parameterized_test.rb
index f52945590b..fdfc20f785 100644
--- a/actionmailer/test/parameterized_test.rb
+++ b/actionmailer/test/parameterized_test.rb
@@ -38,4 +38,18 @@ class ParameterizedTest < ActiveSupport::TestCase
@mail.deliver_later
end
end
+
+ test "respond_to?" do
+ mailer = ParamsMailer.with(inviter: "david@basecamp.com", invitee: "jason@basecamp.com")
+
+ assert_respond_to mailer, :invitation
+ assert_not_respond_to mailer, :anything
+
+ invitation = mailer.method(:invitation)
+ assert_equal Method, invitation.class
+
+ assert_raises(NameError) do
+ invitation = mailer.method(:anything)
+ end
+ end
end