mirror of https://github.com/rails/rails
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:
parent
eeb2cfb686
commit
af0733a8e7
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue