From 15c466dd729e744379380d08b8c25b9860fd836d Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Fri, 2 Mar 2007 23:39:29 +0000 Subject: Split out the basic plugin locator functionality into an abstract super class. Add a FileSystemLocator to do the job of checking the plugin_paths for plugins. Add plugin_locators configuration option which will iterate over the set of plugin locators and load each of the plugin loaders they return. Rename locater everywhere to locator. [Marcel Molina Jr.] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6290 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/test/plugin_loader_test.rb | 9 ++++++- railties/test/plugin_locater_test.rb | 51 ------------------------------------ railties/test/plugin_locator_test.rb | 41 +++++++++++++++++++++++++++++ railties/test/plugin_test_helper.rb | 4 +++ 4 files changed, 53 insertions(+), 52 deletions(-) delete mode 100644 railties/test/plugin_locater_test.rb create mode 100644 railties/test/plugin_locator_test.rb (limited to 'railties/test') diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb index 7010a60298..911f854f75 100644 --- a/railties/test/plugin_loader_test.rb +++ b/railties/test/plugin_loader_test.rb @@ -7,6 +7,13 @@ class TestPluginLoader < Test::Unit::TestCase @empty_plugin_path = plugin_fixture_path('default/empty') end + def test_determining_if_the_plugin_order_has_been_explicitly_set + loader = loader_for(@valid_plugin_path) + assert !loader.send(:explicit_plugin_loading_order?) + only_load_the_following_plugins! %w(stubby acts_as_chunky_bacon) + assert loader.send(:explicit_plugin_loading_order?) + end + def test_determining_whether_a_given_plugin_is_loaded plugin_loader = loader_for(@valid_plugin_path) assert !plugin_loader.loaded? @@ -44,7 +51,7 @@ class TestPluginLoader < Test::Unit::TestCase end def test_loading_a_plugin_gives_the_init_file_access_to_all_it_needs - failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the SubbyMixin constant defined already." + failure_tip = "Perhaps someone has written another test that loads this same plugin and therefore makes the StubbyMixin constant defined already." assert !defined?(StubbyMixin), failure_tip assert !added_to_load_path?(@valid_plugin_path) # The init.rb of this plugin raises if it doesn't have access to all the things it needs diff --git a/railties/test/plugin_locater_test.rb b/railties/test/plugin_locater_test.rb deleted file mode 100644 index ba843a8e45..0000000000 --- a/railties/test/plugin_locater_test.rb +++ /dev/null @@ -1,51 +0,0 @@ -require File.dirname(__FILE__) + '/plugin_test_helper' - -class TestPluginLocater < Test::Unit::TestCase - def setup - configuration = Rails::Configuration.new - # We need to add our testing plugin directory to the plugin paths so - # the locater knows where to look for our plugins - configuration.plugin_paths << plugin_fixture_root_path - @initializer = Rails::Initializer.new(configuration) - @locater = new_locater - end - - def test_determining_if_the_plugin_order_has_been_explicitly_set - assert !@locater.send(:explicit_plugin_loading_order?) - only_load_the_following_plugins! %w(stubby acts_as_chunky_bacon) - assert @locater.send(:explicit_plugin_loading_order?) - end - - def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list - only_load_the_following_plugins! [] - assert_equal [], @locater.plugins - end - - def test_only_the_specified_plugins_are_located_in_the_order_listed - plugin_names = %w(stubby acts_as_chunky_bacon) - only_load_the_following_plugins! plugin_names - assert_equal plugin_names, @locater.plugin_names - end - - def test_registering_a_plugin_name_that_does_not_exist_raisesa_load_error - only_load_the_following_plugins! %w(stubby acts_as_non_existant_plugin) - assert_raises(LoadError) do - @locater.plugin_names - end - 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), @locater.plugin_names, failure_tip - end - - private - def new_locater(initializer = @initializer) - Rails::Plugin::Locater.new(initializer) - end - - def only_load_the_following_plugins!(plugins) - @initializer.configuration.plugins = plugins - end - -end \ No newline at end of file diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb new file mode 100644 index 0000000000..5ea89844d0 --- /dev/null +++ b/railties/test/plugin_locator_test.rb @@ -0,0 +1,41 @@ +require File.dirname(__FILE__) + '/plugin_test_helper' + +class TestPluginFileSystemLocator < Test::Unit::TestCase + def setup + configuration = Rails::Configuration.new + # We need to add our testing plugin directory to the plugin paths so + # the locator knows where to look for our plugins + configuration.plugin_paths << plugin_fixture_root_path + @initializer = Rails::Initializer.new(configuration) + @locator = new_locator + end + + def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list + only_load_the_following_plugins! [] + assert_equal [], @locator.plugins + end + + def test_only_the_specified_plugins_are_located_in_the_order_listed + plugin_names = %w(stubby acts_as_chunky_bacon) + only_load_the_following_plugins! plugin_names + assert_equal plugin_names, @locator.plugin_names + 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) + assert_raises(LoadError) do + @locator.plugins + end + 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 + end + + private + def new_locator(initializer = @initializer) + Rails::Plugin::FileSystemLocator.new(initializer) + end + +end \ No newline at end of file diff --git a/railties/test/plugin_test_helper.rb b/railties/test/plugin_test_helper.rb index 58649ea2fa..0b065a5444 100644 --- a/railties/test/plugin_test_helper.rb +++ b/railties/test/plugin_test_helper.rb @@ -11,4 +11,8 @@ class Test::Unit::TestCase def plugin_fixture_root_path File.join(File.dirname(__FILE__), 'fixtures', 'plugins') end + + def only_load_the_following_plugins!(plugins) + @initializer.configuration.plugins = plugins + end end \ No newline at end of file -- cgit v1.2.3