diff options
-rw-r--r-- | railties/lib/rails/plugin.rb | 19 | ||||
-rw-r--r-- | railties/test/railties/plugin_test.rb | 33 |
2 files changed, 46 insertions, 6 deletions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 98f329cc17..5d6144959d 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -47,13 +47,20 @@ module Rails end initializer :load_init_rb, :before => :load_application_initializers do |app| - files = %w(rails/init.rb init.rb).map { |path| File.expand_path path, root } - if initrb = files.find { |path| File.file? path } - if initrb == files.first - ActiveSupport::Deprecation.warn "Use toplevel init.rb; rails/init.rb is deprecated: #{initrb}" + initializers = Dir["#{root}/lib/rails/initializers/*.rb"] + + if initializers.any? + initializers.each do |initializer| + config = app.config + eval(File.read(initializer), binding, initializer) + end + else + files = %w(rails/init.rb init.rb).map { |path| File.expand_path path, root } + if initrb = files.find { |path| File.file? path } + ActiveSupport::Deprecation.warn "init.rb is deprecated: #{initrb}. Use lib/rails/initializers/#{name}.rb" + config = app.config + eval(File.read(initrb), binding, initrb) end - config = app.config - eval(File.read(initrb), binding, initrb) end end diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb index 0f5f29468c..4ea5460a68 100644 --- a/railties/test/railties/plugin_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -94,6 +94,39 @@ module RailtiesTest assert rescued, "Expected boot rails to fail" end + test "loads lib/rails/initializers/foo.rb" do + @plugin.write "lib/rails/initializers/foo.rb", <<-RUBY + $loaded = true + RUBY + + boot_rails + assert $loaded + end + + test "loads vendored rails/initializers/foo thats already in the $LOAD_PATH" do + $: << "#{app_path}/vendor/foo/lib" + + app_file "vendor/foo/lib/rails/initializers/foo.rb", <<-RUBY + $loaded = true + RUBY + + boot_rails + assert $loaded + end + + test "skips init.rb if initializer is present" do + @plugin.write "lib/rails/initializers/foo.rb", <<-RUBY + $loaded = true + RUBY + + @plugin.write "init.rb", <<-RUBY + raise "b00m" + RUBY + + boot_rails + assert $loaded + end + test "loads deprecated rails/init.rb" do @plugin.write "rails/init.rb", <<-RUBY $loaded = true |