diff options
author | Piotr Sarnacki <drogus@gmail.com> | 2010-07-14 13:38:36 +0200 |
---|---|---|
committer | Piotr Sarnacki <drogus@gmail.com> | 2010-09-03 22:59:04 +0200 |
commit | 15f95b98ac048407a1ce6873bb02fc5fbb6c991c (patch) | |
tree | ac71786040f34181e1297852ef63334ac4b336ee | |
parent | efe9555cd77b409c6965bf803a47b1230ee7dec7 (diff) | |
download | rails-15f95b98ac048407a1ce6873bb02fc5fbb6c991c.tar.gz rails-15f95b98ac048407a1ce6873bb02fc5fbb6c991c.tar.bz2 rails-15f95b98ac048407a1ce6873bb02fc5fbb6c991c.zip |
Ensure that plugins are not loaded twice
-rw-r--r-- | railties/lib/rails/plugin.rb | 9 | ||||
-rw-r--r-- | railties/test/railties/engine_test.rb | 38 |
2 files changed, 47 insertions, 0 deletions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb index 4dab1c0b53..22a0eb10a8 100644 --- a/railties/lib/rails/plugin.rb +++ b/railties/lib/rails/plugin.rb @@ -18,6 +18,10 @@ module Rails # root during the boot process. # class Plugin < Engine + def self.global_plugins + @global_plugins ||= [] + end + def self.inherited(base) raise "You cannot inherit from Rails::Plugin" end @@ -28,6 +32,11 @@ module Rails Dir["#{path}/*"].each do |plugin_path| plugin = new(plugin_path) next unless list.include?(plugin.name) || list.include?(:all) + if global_plugins.include?(plugin.name) + warn "WARNING: plugin #{plugin.name} from #{path} was not loaded. Plugin with the same name has been already loaded." + next + end + global_plugins << plugin.name plugins << plugin end end diff --git a/railties/test/railties/engine_test.rb b/railties/test/railties/engine_test.rb index 39189edaa3..980265d969 100644 --- a/railties/test/railties/engine_test.rb +++ b/railties/test/railties/engine_test.rb @@ -1,8 +1,23 @@ require "isolation/abstract_unit" require "railties/shared_tests" +require 'stringio' module RailtiesTest class EngineTest < Test::Unit::TestCase + # TODO: it's copied from generators/test_case, maybe make a module with such helpers? + def capture(stream) + begin + stream = stream.to_s + eval "$#{stream} = StringIO.new" + yield + result = eval("$#{stream}").string + ensure + eval("$#{stream} = #{stream.upcase}") + end + + result + end + include ActiveSupport::Testing::Isolation include SharedTests @@ -126,5 +141,28 @@ module RailtiesTest assert Bukkits::Engine.config.yaffle_loaded end + + test "engine does not load plugins that already exists in application" do + @plugin.write "lib/bukkits.rb", <<-RUBY + class Bukkits + class Engine < ::Rails::Engine + end + end + RUBY + + @plugin.write "vendor/plugins/yaffle/init.rb", <<-RUBY + config.engine_yaffle_loaded = true + RUBY + + app_file "vendor/plugins/yaffle/init.rb", <<-RUBY + config.app_yaffle_loaded = true + RUBY + + warnings = capture(:stderr) { boot_rails } + + assert !warnings.empty? + assert !Bukkits::Engine.config.respond_to?(:engine_yaffle_loaded) + assert Rails.application.config.app_yaffle_loaded + end end end |