File tree Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -482,8 +482,6 @@ What is described above are the defaults with a newly generated Rails app. There
482
482
483
483
See also [ Autoloading in the Test Environment] ( #autoloading-in-the-test-environment ) .
484
484
485
- ` config.autoload_paths ` is not changeable from environment-specific configuration files.
486
-
487
485
The value of ` autoload_paths ` can be inspected. In a just-generated application
488
486
it is (edited):
489
487
Original file line number Diff line number Diff line change @@ -559,6 +559,12 @@ def load_seed
559
559
end
560
560
end
561
561
562
+ initializer :load_environment_config , before : :load_environment_hook , group : :all do
563
+ paths [ "config/environments" ] . existent . each do |environment |
564
+ require environment
565
+ end
566
+ end
567
+
562
568
initializer :set_load_path , before : :bootstrap_hook do |app |
563
569
_all_load_paths ( app . config . add_autoload_paths_to_load_path ) . reverse_each do |path |
564
570
$LOAD_PATH. unshift ( path ) if File . directory? ( path )
@@ -607,12 +613,6 @@ def load_seed
607
613
end
608
614
end
609
615
610
- initializer :load_environment_config , before : :load_environment_hook , group : :all do
611
- paths [ "config/environments" ] . existent . each do |environment |
612
- require environment
613
- end
614
- end
615
-
616
616
initializer :prepend_helpers_path do |app |
617
617
if !isolated? || ( app == self )
618
618
app . config . helpers_paths . unshift ( *paths [ "app/helpers" ] . existent )
Original file line number Diff line number Diff line change @@ -1751,6 +1751,31 @@ def index
1751
1751
assert_empty Rails . configuration . paths . load_paths - $LOAD_PATH
1752
1752
end
1753
1753
1754
+ test "autoload paths can be set in the config file of the environment" do
1755
+ app_dir "custom_autoload_path"
1756
+ app_dir "custom_autoload_once_path"
1757
+ app_dir "custom_eager_load_path"
1758
+
1759
+ restore_default_config
1760
+ add_to_env_config "development" , <<-RUBY
1761
+ config.autoload_paths << "#{ app_path } /custom_autoload_path"
1762
+ config.autoload_once_paths << "#{ app_path } /custom_autoload_once_path"
1763
+ config.eager_load_paths << "#{ app_path } /custom_eager_load_path"
1764
+ RUBY
1765
+
1766
+ app "development"
1767
+
1768
+ Rails . application . config . tap do |config |
1769
+ assert_includes config . autoload_paths , "#{ app_path } /custom_autoload_path"
1770
+ assert_includes config . autoload_once_paths , "#{ app_path } /custom_autoload_once_path"
1771
+ assert_includes config . eager_load_paths , "#{ app_path } /custom_eager_load_path"
1772
+ end
1773
+
1774
+ assert_includes $LOAD_PATH, "#{ app_path } /custom_autoload_path"
1775
+ assert_includes $LOAD_PATH, "#{ app_path } /custom_autoload_once_path"
1776
+ assert_includes $LOAD_PATH, "#{ app_path } /custom_eager_load_path"
1777
+ end
1778
+
1754
1779
test "autoloading during initialization gets deprecation message and clearing if config.cache_classes is false" do
1755
1780
app_file "lib/c.rb" , <<~EOS
1756
1781
class C
You can’t perform that action at this time.
0 commit comments