Added symbols as a legal way of specifying plugins in config.plugins (closes #9629) [tom]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7540 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 e38ad5dd
......@@ -5,6 +5,8 @@
# Loads :classic_pagination before all the other plugins
config.plugins = [ :classic_pagination, :all ]
* Added symbols as a legal way of specifying plugins in config.plugins #9629 [tom]
* Removed deprecated task names, like clear_logs, in favor of the new namespaced style [DHH]
* Support multiple config.after_initialize blocks so plugins and apps can more easily cooperate. #9582 [zdennis]
......
......@@ -429,7 +429,10 @@ class Configuration
# The list of plugins to load. If this is set to <tt>nil</tt>, all plugins will
# be loaded. If this is set to <tt>[]</tt>, no plugins will be loaded. Otherwise,
# plugins will be loaded in the order specified.
attr_accessor :plugins
attr_reader :plugins
def plugins=(plugins)
@plugins = plugins.nil? ? nil : plugins.map { |p| p.to_sym }
end
# The path to the root of the plugins directory. By default, it is in
# <tt>vendor/plugins</tt>.
......
......@@ -13,7 +13,7 @@ def load(*args)
def initialize(initializer, directory)
@initializer = initializer
@directory = directory
@name = File.basename(directory)
@name = File.basename(directory).to_sym
end
def load
......@@ -126,7 +126,7 @@ def <=>(other_plugin_loader)
end
if !explicitly_enabled? && !other_plugin_loader.explicitly_enabled?
name <=> other_plugin_loader.name
name.to_s <=> other_plugin_loader.name.to_s
elsif registered_plugins.include?(:all) && (!explicitly_enabled? || !other_plugin_loader.explicitly_enabled?)
effective_index = explicitly_enabled? ? registered_plugins.index(name) : registered_plugins.index(:all)
other_effective_index = other_plugin_loader.explicitly_enabled? ?
......@@ -138,7 +138,7 @@ def <=>(other_plugin_loader)
end
else
name <=> other_plugin_loader.name
name.to_s <=> other_plugin_loader.name.to_s
end
end
end
......
......@@ -16,33 +16,39 @@ def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
end
def test_only_the_specified_plugins_are_located_in_the_order_listed
plugin_names = %w(stubby acts_as_chunky_bacon)
plugin_names = [:stubby, :acts_as_chunky_bacon]
only_load_the_following_plugins! plugin_names
assert_equal plugin_names, @locator.plugin_names
end
def test_all_plugins_are_loaded_when_registered_plugin_list_is_untouched
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
assert_equal %w(a acts_as_chunky_bacon plugin_with_no_lib_dir stubby), @locator.plugin_names, failure_tip
assert_equal [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @locator.plugin_names, failure_tip
end
def test_all_plugins_loaded_when_all_is_used
plugin_names = ['stubby', 'acts_as_chunky_bacon', :all]
plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
only_load_the_following_plugins! plugin_names
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
assert_equal %w(stubby acts_as_chunky_bacon a plugin_with_no_lib_dir), @locator.plugin_names, failure_tip
assert_equal [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @locator.plugin_names, failure_tip
end
def test_all_plugins_loaded_after_all
plugin_names = ['stubby', :all, 'acts_as_chunky_bacon']
plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
only_load_the_following_plugins! plugin_names
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
assert_equal %w(stubby a plugin_with_no_lib_dir acts_as_chunky_bacon ), @locator.plugin_names, failure_tip
assert_equal [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @locator.plugin_names, failure_tip
end
def test_plugin_names_may_be_strings
plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
only_load_the_following_plugins! plugin_names
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
assert_equal [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @locator.plugin_names, failure_tip
end
def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
only_load_the_following_plugins! %w(stubby acts_as_a_non_existant_plugin)
only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
assert_raises(LoadError) do
@initializer.load_plugins
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册