diff options
-rw-r--r-- | railties/CHANGELOG | 2 | ||||
-rw-r--r-- | railties/lib/initializer.rb | 5 | ||||
-rw-r--r-- | railties/lib/rails/plugin/loader.rb | 6 | ||||
-rw-r--r-- | railties/test/plugin_locator_test.rb | 20 |
4 files changed, 22 insertions, 11 deletions
diff --git a/railties/CHANGELOG b/railties/CHANGELOG index 0b453b34aa..bfa37aaf0f 100644 --- a/railties/CHANGELOG +++ b/railties/CHANGELOG @@ -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] diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb index 111b5237ba..3183b0a34a 100644 --- a/railties/lib/initializer.rb +++ b/railties/lib/initializer.rb @@ -429,7 +429,10 @@ module Rails # 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>. diff --git a/railties/lib/rails/plugin/loader.rb b/railties/lib/rails/plugin/loader.rb index e935f9b34b..016bcc6c50 100644 --- a/railties/lib/rails/plugin/loader.rb +++ b/railties/lib/rails/plugin/loader.rb @@ -13,7 +13,7 @@ module Rails 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 @@ module Rails 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 @@ module Rails end else - name <=> other_plugin_loader.name + name.to_s <=> other_plugin_loader.name.to_s end end end diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb index cf6c0d9507..3ac4493d47 100644 --- a/railties/test/plugin_locator_test.rb +++ b/railties/test/plugin_locator_test.rb @@ -16,33 +16,39 @@ class TestPluginFileSystemLocator < Test::Unit::TestCase 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 |