2007-03-01 19:20:32 -05:00
|
|
|
require File.dirname(__FILE__) + '/plugin_test_helper'
|
|
|
|
|
2007-03-02 18:39:29 -05:00
|
|
|
class TestPluginFileSystemLocator < Test::Unit::TestCase
|
2007-03-01 19:20:32 -05:00
|
|
|
def setup
|
|
|
|
configuration = Rails::Configuration.new
|
|
|
|
# We need to add our testing plugin directory to the plugin paths so
|
2007-03-02 18:39:29 -05:00
|
|
|
# the locator knows where to look for our plugins
|
2007-03-01 19:20:32 -05:00
|
|
|
configuration.plugin_paths << plugin_fixture_root_path
|
|
|
|
@initializer = Rails::Initializer.new(configuration)
|
2007-03-02 18:39:29 -05:00
|
|
|
@locator = new_locator
|
2007-03-01 19:20:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
|
|
|
|
only_load_the_following_plugins! []
|
2007-03-02 18:39:29 -05:00
|
|
|
assert_equal [], @locator.plugins
|
2007-03-01 19:20:32 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_only_the_specified_plugins_are_located_in_the_order_listed
|
2007-09-22 13:08:09 -04:00
|
|
|
plugin_names = [:stubby, :acts_as_chunky_bacon]
|
2007-03-01 19:20:32 -05:00
|
|
|
only_load_the_following_plugins! plugin_names
|
2007-03-02 18:39:29 -05:00
|
|
|
assert_equal plugin_names, @locator.plugin_names
|
2007-03-01 19:20:32 -05:00
|
|
|
end
|
|
|
|
|
2007-03-02 21:53:06 -05:00
|
|
|
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"
|
2007-09-22 13:08:09 -04:00
|
|
|
assert_equal [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @locator.plugin_names, failure_tip
|
2007-03-02 21:53:06 -05:00
|
|
|
end
|
|
|
|
|
2007-09-21 18:31:19 -04:00
|
|
|
def test_all_plugins_loaded_when_all_is_used
|
2007-09-22 13:08:09 -04:00
|
|
|
plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
|
2007-09-21 18:31:19 -04:00
|
|
|
only_load_the_following_plugins! plugin_names
|
|
|
|
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
|
2007-09-22 13:08:09 -04:00
|
|
|
assert_equal [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @locator.plugin_names, failure_tip
|
2007-09-21 18:31:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_all_plugins_loaded_after_all
|
2007-09-22 13:08:09 -04:00
|
|
|
plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
|
2007-09-21 18:31:19 -04:00
|
|
|
only_load_the_following_plugins! plugin_names
|
|
|
|
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
|
2007-09-22 13:08:09 -04:00
|
|
|
assert_equal [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @locator.plugin_names, failure_tip
|
2007-09-21 18:31:19 -04:00
|
|
|
end
|
|
|
|
|
2007-09-22 13:08:09 -04:00
|
|
|
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
|
2007-03-02 21:53:06 -05:00
|
|
|
|
2007-03-02 18:39:29 -05:00
|
|
|
def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
|
2007-09-22 13:08:09 -04:00
|
|
|
only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin]
|
2007-03-01 19:20:32 -05:00
|
|
|
assert_raises(LoadError) do
|
2007-03-02 21:53:06 -05:00
|
|
|
@initializer.load_plugins
|
2007-03-01 19:20:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2007-03-02 18:39:29 -05:00
|
|
|
def new_locator(initializer = @initializer)
|
|
|
|
Rails::Plugin::FileSystemLocator.new(initializer)
|
2007-03-02 21:53:06 -05:00
|
|
|
end
|
2007-03-01 19:20:32 -05:00
|
|
|
end
|