diff options
author | Joshua Peek <josh@joshpeek.com> | 2010-03-23 15:36:32 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2010-03-23 15:36:32 -0500 |
commit | e47a1d7865f40ae70a4c38e7ea792843641f3bcb (patch) | |
tree | fb5caf1e0d4281b60b9effe1ab393cd9629298b6 | |
parent | b9f551ac156effdc33416bcf479a8149e2419aab (diff) | |
download | rails-e47a1d7865f40ae70a4c38e7ea792843641f3bcb.tar.gz rails-e47a1d7865f40ae70a4c38e7ea792843641f3bcb.tar.bz2 rails-e47a1d7865f40ae70a4c38e7ea792843641f3bcb.zip |
Load plugin initializers from lib/rails/initializers/*.rb
-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 |