Make sure respond_to? and method_missing works in abstract Railties

Those methods were raising an confusing exception when trying to call
`Rails::Railtie.respond_to?(:something)`. Now they just work.

Fixes #44761
This commit is contained in:
Rafael Mendonça França 2022-03-25 23:56:34 +00:00
parent eeb2cfb686
commit af0733a8e7
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
2 changed files with 12 additions and 2 deletions

View File

@ -214,13 +214,15 @@ module Rails
end
def respond_to_missing?(name, _)
return super if abstract_railtie?
instance.respond_to?(name) || super
end
# If the class method does not have a method, then send the method call
# to the Railtie instance.
def method_missing(name, *args, &block)
if instance.respond_to?(name)
if !abstract_railtie? && instance.respond_to?(name)
instance.public_send(name, *args, &block)
else
super

View File

@ -21,7 +21,15 @@ module RailtiesTest
end
test "cannot instantiate a Railtie object" do
assert_raise(RuntimeError) { Rails::Railtie.new }
assert_raise(RuntimeError) { Rails::Railtie.send(:new) }
end
test "respond_to? works in the abstract railties" do
assert_not_respond_to Rails::Railtie, :something_nice
end
test "method_missing works in the abstract railties" do
assert_raise(NoMethodError) { Rails::Railtie.something_nice }
end
test "Railtie provides railtie_name" do