From 23fd1f12801c8585ff3b114e74264b67ad6264e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 17 Feb 2010 00:15:21 +0100 Subject: [PATCH] Show deprecation message for rails/init.rb in plugins. --- railties/lib/rails/plugin.rb | 10 ++++++++-- railties/test/railties/plugin_test.rb | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 64d03e7599..882f2dc28e 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -29,7 +29,7 @@ module Rails unless extra_tasks.empty? ActiveSupport::Deprecation.warn "Having rake tasks in PLUGIN_PATH/tasks or " << - "PLUGIN_PATH/rails/tasks is deprecated. Use to PLUGIN_PATH/lib/tasks instead" + "PLUGIN_PATH/rails/tasks is deprecated. Use PLUGIN_PATH/lib/tasks instead" extra_tasks.sort.each { |ext| load(ext) } end end @@ -44,7 +44,13 @@ module Rails end initializer :load_init_rb, :before => :load_application_initializers do |app| - file = Dir["#{root}/{rails/init,init}.rb"].first + if File.file?(file = File.expand_path("rails/init.rb", root)) + ActiveSupport::Deprecation.warn "PLUGIN_PATH/rails/init.rb in plugins is deprecated. " << + "Use PLUGIN_PATH/init.rb instead" + else + file = File.expand_path("init.rb", root) + end + config = app.config eval(File.read(file), binding, file) if file && File.file?(file) end diff --git a/railties/test/railties/plugin_test.rb b/railties/test/railties/plugin_test.rb index 09b859dcdd..0f5f29468c 100644 --- a/railties/test/railties/plugin_test.rb +++ b/railties/test/railties/plugin_test.rb @@ -94,6 +94,15 @@ module RailtiesTest assert rescued, "Expected boot rails to fail" end + test "loads deprecated rails/init.rb" do + @plugin.write "rails/init.rb", <<-RUBY + $loaded = true + RUBY + + boot_rails + assert $loaded + end + test "deprecated tasks are also loaded" do $executed = false @plugin.write "tasks/foo.rake", <<-RUBY