From 2a116ec6f5534ba2e883681bc0c3cbe09c840211 Mon Sep 17 00:00:00 2001 From: Jason Frey Date: Tue, 19 Nov 2019 21:20:43 -0500 Subject: [PATCH] Raise exception if nested file will never be found It is possible to give autoload an invalid path, and that issue will never be found until the associated constant is vivified. This causes issues where people forget to remove the require_nested calls when they remove the files. Now, it's not possible to forget, because an exception will be raised as soon as the parent file is loaded. --- lib/extensions/require_nested.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/extensions/require_nested.rb b/lib/extensions/require_nested.rb index 95cc7a3459d..2a038f3d510 100644 --- a/lib/extensions/require_nested.rb +++ b/lib/extensions/require_nested.rb @@ -6,6 +6,7 @@ def require_nested(name) filename = "#{self}::#{name}".underscore filename = name.to_s.underscore if self == Object if Rails.application.config.cache_classes + raise LoadError, "No such file to load -- #{filename}" unless ActiveSupport::Dependencies.search_for_file(filename) autoload name, filename else require_dependency filename