aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/plugin_loader_test.rb
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2007-03-02 00:20:32 +0000
committerMarcel Molina <marcel@vernix.org>2007-03-02 00:20:32 +0000
commitb0e1430c523cf09155f72d5996be2cc2bf8e2eb7 (patch)
treec1f0dfd39794fa284737386f6c7520529e581b3b /railties/test/plugin_loader_test.rb
parent36cf67e8e50056e178f2d43705a324778fddfd0f (diff)
downloadrails-b0e1430c523cf09155f72d5996be2cc2bf8e2eb7.tar.gz
rails-b0e1430c523cf09155f72d5996be2cc2bf8e2eb7.tar.bz2
rails-b0e1430c523cf09155f72d5996be2cc2bf8e2eb7.zip
Split plugin location and loading out of the initializer and into a new Plugin namespace, which includes Plugin::Locater and Plugin::Loader. The loader class that is used can be customized using the config.plugin_loader option. Those monkey patching the plugin loading subsystem take note, the internals changing here will likely break your modifications. The good news is that it should be substantially easier to hook into the plugin locating and loading process now. [Marcel Molina Jr.]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6277 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/test/plugin_loader_test.rb')
-rw-r--r--railties/test/plugin_loader_test.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
new file mode 100644
index 0000000000..7010a60298
--- /dev/null
+++ b/railties/test/plugin_loader_test.rb
@@ -0,0 +1,71 @@
+require File.dirname(__FILE__) + '/plugin_test_helper'
+
+class TestPluginLoader < Test::Unit::TestCase
+ def setup
+ @initializer = Rails::Initializer.new(Rails::Configuration.new)
+ @valid_plugin_path = plugin_fixture_path('default/stubby')
+ @empty_plugin_path = plugin_fixture_path('default/empty')
+ end
+
+ def test_determining_whether_a_given_plugin_is_loaded
+ plugin_loader = loader_for(@valid_plugin_path)
+ assert !plugin_loader.loaded?
+ assert_nothing_raised do
+ plugin_loader.send(:register_plugin_as_loaded)
+ end
+ assert plugin_loader.loaded?
+ end
+
+ def test_if_a_path_is_a_plugin_path
+ # This is a plugin path, with a lib dir
+ assert loader_for(@valid_plugin_path).plugin_path?
+ # This just has an init.rb and no lib dir
+ assert loader_for(plugin_fixture_path('default/plugin_with_no_lib_dir')).plugin_path?
+ # This would be a plugin path, but the directory is empty
+ assert !loader_for(plugin_fixture_path('default/empty')).plugin_path?
+ # This is a non sense path
+ assert !loader_for(plugin_fixture_path('default/this_directory_does_not_exist')).plugin_path?
+ end
+
+ def test_if_you_try_to_load_a_non_plugin_path_you_get_a_load_error
+ # This path is fine so nothing is raised
+ assert_nothing_raised do
+ loader_for(@valid_plugin_path).send(:report_nonexistant_or_empty_plugin!)
+ end
+
+ # This is an empty path so it raises
+ assert_raises(LoadError) do
+ loader_for(@empty_plugin_path).send(:report_nonexistant_or_empty_plugin!)
+ end
+
+ assert_raises(LoadError) do
+ loader_for('this_is_not_a_plugin_directory').send(:report_nonexistant_or_empty_plugin!)
+ end
+ 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."
+ 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
+ assert_nothing_raised do
+ loader_for(@valid_plugin_path).load
+ end
+ assert added_to_load_path?(@valid_plugin_path)
+ assert defined?(StubbyMixin)
+ end
+
+ private
+ def loader_for(path, initializer = @initializer)
+ Rails::Plugin::Loader.new(initializer, path)
+ end
+
+ def plugin_fixture_path(path)
+ File.join(plugin_fixture_root_path, path)
+ end
+
+ def added_to_load_path?(path)
+ $LOAD_PATH.grep(/#{path}/).size == 1
+ end
+
+end \ No newline at end of file