File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
test/application/initializers Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,7 @@ def inherited(base)
67
67
raise "You cannot have more than one Rails::Application" if Rails . application
68
68
super
69
69
Rails . application = base . instance
70
+ Rails . application . add_lib_to_load_paths!
70
71
ActiveSupport . run_load_hooks ( :before_configuration , base . instance )
71
72
end
72
73
@@ -83,11 +84,21 @@ def method_missing(*args, &block)
83
84
84
85
delegate :middleware , :to => :config
85
86
87
+ def add_lib_to_load_paths!
88
+ path = config . root . join ( 'lib' ) . to_s
89
+ $LOAD_PATH. unshift ( path ) if File . exists? ( path )
90
+ end
91
+
86
92
def require_environment!
87
93
environment = paths . config . environment . to_a . first
88
94
require environment if environment
89
95
end
90
96
97
+ def eager_load!
98
+ railties . all ( &:eager_load! )
99
+ super
100
+ end
101
+
91
102
def routes
92
103
@routes ||= ActionDispatch ::Routing ::RouteSet . new
93
104
end
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ module Finisher
38
38
initializer :eager_load! do
39
39
if config . cache_classes && !$rails_rake_task
40
40
ActiveSupport . run_load_hooks ( :before_eager_load , self )
41
- railties . all ( & : eager_load!)
41
+ eager_load!
42
42
end
43
43
end
44
44
Original file line number Diff line number Diff line change @@ -19,6 +19,23 @@ def setup
19
19
assert $:. include? ( "#{ app_path } /app/models" )
20
20
end
21
21
22
+ test "initializing an application adds lib path on inheritance hook" do
23
+ app_file "lib/foo.rb" , <<-RUBY
24
+ module Foo; end
25
+ RUBY
26
+
27
+ add_to_config <<-RUBY
28
+ require "foo"
29
+ raise "Expected Foo to be defined" unless defined?(Foo)
30
+ RUBY
31
+
32
+ assert_nothing_raised do
33
+ require "#{ app_path } /config/environment"
34
+ end
35
+
36
+ assert $:. include? ( "#{ app_path } /lib" )
37
+ end
38
+
22
39
test "initializing an application eager load any path under app" do
23
40
app_file "app/anything/foo.rb" , <<-RUBY
24
41
module Foo; end
You can’t perform that action at this time.
0 commit comments