1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ensure that plugins are not loaded twice

This commit is contained in:
Piotr Sarnacki 2010-07-14 13:38:36 +02:00
parent efe9555cd7
commit 15f95b98ac
2 changed files with 47 additions and 0 deletions

View file

@ -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

View file

@ -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