2008-01-05 08:33:00 -05:00
|
|
|
require 'plugin_test_helper'
|
2007-03-01 19:20:32 -05:00
|
|
|
|
2009-10-08 21:12:28 -04:00
|
|
|
# TODO: Rewrite all these tests
|
|
|
|
class FakeInitializerSlashApplication
|
|
|
|
attr_reader :config
|
|
|
|
alias configuration config
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@config = Rails::Configuration.new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
class PluginLocatorTest < Test::Unit::TestCase
|
|
|
|
def test_should_require_subclasses_to_implement_the_plugins_method
|
2009-03-08 16:11:58 -04:00
|
|
|
assert_raise(RuntimeError) do
|
2009-02-03 21:25:37 -05:00
|
|
|
Rails::Plugin::Locator.new(nil).plugins
|
2007-11-08 00:29:44 -05:00
|
|
|
end
|
2009-02-03 21:25:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_iterator_over_plugins_returned_by_plugins_when_calling_each
|
|
|
|
locator = Rails::Plugin::Locator.new(nil)
|
|
|
|
locator.stubs(:plugins).returns([:a, :b, :c])
|
|
|
|
plugin_consumer = mock
|
|
|
|
plugin_consumer.expects(:consume).with(:a)
|
|
|
|
plugin_consumer.expects(:consume).with(:b)
|
|
|
|
plugin_consumer.expects(:consume).with(:c)
|
2007-03-01 19:20:32 -05:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
locator.each do |plugin|
|
|
|
|
plugin_consumer.consume(plugin)
|
2007-11-08 00:29:44 -05:00
|
|
|
end
|
2007-03-02 21:53:06 -05:00
|
|
|
end
|
2009-02-03 21:25:37 -05:00
|
|
|
end
|
2007-11-08 00:29:44 -05:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
class PluginFileSystemLocatorTest < Test::Unit::TestCase
|
|
|
|
def setup
|
2009-10-08 21:12:28 -04:00
|
|
|
@initializer = FakeInitializerSlashApplication.new
|
|
|
|
@configuration = @initializer.config
|
|
|
|
Rails.application = @initializer
|
2009-02-03 21:25:37 -05:00
|
|
|
# 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
|
|
|
|
@locator = Rails::Plugin::FileSystemLocator.new(@initializer)
|
|
|
|
@valid_plugin_path = plugin_fixture_path('default/stubby')
|
|
|
|
@empty_plugin_path = plugin_fixture_path('default/empty')
|
|
|
|
end
|
2007-11-08 00:29:44 -05:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_should_return_rails_plugin_instances_when_calling_create_plugin_with_a_valid_plugin_directory
|
|
|
|
assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path)
|
|
|
|
end
|
2007-11-08 00:29:44 -05:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory
|
|
|
|
assert_nil @locator.send(:create_plugin, @empty_plugin_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_return_all_plugins_found_under_the_set_plugin_paths
|
2009-04-22 22:35:58 -04:00
|
|
|
assert_equal ["a", "acts_as_chunky_bacon", "engine", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map { |p| p.name }.sort
|
2009-02-03 21:25:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration
|
|
|
|
@configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")]
|
2009-04-22 22:35:58 -04:00
|
|
|
assert_equal ["acts_as_chunky_bacon", "gemlike", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map { |p| p.name }.sort
|
2007-03-02 21:53:06 -05:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
@configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
|
2009-04-22 22:50:24 -04:00
|
|
|
assert_equal ["a"], @locator.plugins.map { |p| p.name }
|
2007-03-01 19:20:32 -05:00
|
|
|
end
|
2007-11-08 00:29:44 -05:00
|
|
|
|
2009-02-03 21:25:37 -05:00
|
|
|
def test_should_not_raise_any_error_and_return_no_plugins_if_the_plugin_path_value_does_not_exist
|
|
|
|
@configuration.plugin_paths = ["some_missing_directory"]
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert @locator.plugins.empty?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|