aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2008-04-21 13:27:19 -0500
committerJoshua Peek <josh@joshpeek.com>2008-04-21 13:27:19 -0500
commit1d09ccd949eb113601ee84c10a508d36c63c62b7 (patch)
treeec8eb4c0b2b61bc0822b3d80f674fab3a75640af /railties
parenteef9002968609a0d8d4a8006aebcd6f18f993f4a (diff)
downloadrails-1d09ccd949eb113601ee84c10a508d36c63c62b7.tar.gz
rails-1d09ccd949eb113601ee84c10a508d36c63c62b7.tar.bz2
rails-1d09ccd949eb113601ee84c10a508d36c63c62b7.zip
Revert "Update plugin loading tests to reflect changes in plugin fixtures."
This reverts commit eef9002968609a0d8d4a8006aebcd6f18f993f4a.
Diffstat (limited to 'railties')
-rw-r--r--railties/test/initializer_test.rb49
-rw-r--r--railties/test/plugin_loader_test.rb89
-rw-r--r--railties/test/plugin_locator_test.rb27
3 files changed, 86 insertions, 79 deletions
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index 31b3255610..0df0164ca6 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -38,27 +38,27 @@ class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::Te
end
config.after_initialize do
$test_after_initialize_block2 = "congratulations"
- end
+ end
assert_nil $test_after_initialize_block1
- assert_nil $test_after_initialize_block2
+ assert_nil $test_after_initialize_block2
Rails::Initializer.run(:after_initialize, config)
end
-
+
def teardown
$test_after_initialize_block1 = nil
- $test_after_initialize_block2 = nil
+ $test_after_initialize_block2 = nil
end
def test_should_have_called_the_first_after_initialize_block
assert_equal "success", $test_after_initialize_block1
end
-
+
def test_should_have_called_the_second_after_initialize_block
assert_equal "congratulations", $test_after_initialize_block2
end
end
-
+
class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::TestCase
def setup
@@ -69,7 +69,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::
config.after_initialize # don't pass a block, this is what we're testing!
config.after_initialize do
$test_after_initialize_block2 = "congratulations"
- end
+ end
assert_nil $test_after_initialize_block1
Rails::Initializer.run(:after_initialize, config)
@@ -77,7 +77,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::
def teardown
$test_after_initialize_block1 = nil
- $test_after_initialize_block2 = nil
+ $test_after_initialize_block2 = nil
end
def test_should_have_called_the_first_after_initialize_block
@@ -95,7 +95,7 @@ uses_mocha 'framework paths' do
def setup
@config = Rails::Configuration.new
@config.frameworks.clear
-
+
File.stubs(:directory?).returns(true)
@config.stubs(:framework_root_path).returns('')
end
@@ -112,7 +112,7 @@ uses_mocha 'framework paths' do
def test_actioncontroller_or_actionview_add_actionpack
@config.frameworks << :action_controller
assert_framework_path '/actionpack/lib'
-
+
@config.frameworks = [:action_view]
assert_framework_path '/actionpack/lib'
end
@@ -162,7 +162,7 @@ uses_mocha "Initializer plugin loading tests" do
end
def test_only_the_specified_plugins_are_located_in_the_order_listed
- plugin_names = [:plugin_with_no_lib_dir]
+ plugin_names = [:plugin_with_no_lib_dir, :acts_as_chunky_bacon]
only_load_the_following_plugins! plugin_names
load_plugins!
assert_plugins plugin_names, @initializer.loaded_plugins
@@ -171,27 +171,27 @@ uses_mocha "Initializer plugin loading tests" do
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"
load_plugins!
- assert_plugins [:plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip
end
def test_all_plugins_loaded_when_all_is_used
- plugin_names = [:stubby, :all]
+ plugin_names = [:stubby, :acts_as_chunky_bacon, :all]
only_load_the_following_plugins! plugin_names
load_plugins!
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins [:stubby, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip
end
def test_all_plugins_loaded_after_all
- plugin_names = [:all, :stubby]
+ plugin_names = [:stubby, :all, :acts_as_chunky_bacon]
only_load_the_following_plugins! plugin_names
load_plugins!
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
- assert_plugins [:plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip
+ assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip
end
def test_plugin_names_may_be_strings
- plugin_names = ['stubby', :plugin_with_no_lib_dir]
+ plugin_names = ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
only_load_the_following_plugins! plugin_names
load_plugins!
failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
@@ -204,21 +204,22 @@ uses_mocha "Initializer plugin loading tests" do
load_plugins!
end
end
-
+
def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
- only_load_the_following_plugins! [:stubby]
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
@initializer.add_plugin_load_paths
-
+
assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
+ assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
end
-
+
private
-
+
def load_plugins!
@initializer.add_plugin_load_paths
@initializer.load_plugins
end
end
-
-end
+
+end
diff --git a/railties/test/plugin_loader_test.rb b/railties/test/plugin_loader_test.rb
index 09d15a577a..30fcacbaa1 100644
--- a/railties/test/plugin_loader_test.rb
+++ b/railties/test/plugin_loader_test.rb
@@ -11,18 +11,18 @@ uses_mocha "Plugin Loader Tests" do
class TestPluginLoader < Test::Unit::TestCase
ORIGINAL_LOAD_PATH = $LOAD_PATH.dup
-
+
def setup
reset_load_path!
-
+
@configuration = Rails::Configuration.new
@configuration.plugin_paths << plugin_fixture_root_path
@initializer = Rails::Initializer.new(@configuration)
@valid_plugin_path = plugin_fixture_path('default/stubby')
@empty_plugin_path = plugin_fixture_path('default/empty')
-
+
@failure_tip = "It's likely someone has added a new plugin fixture without updating this list"
-
+
@loader = Rails::Plugin::Loader.new(@initializer)
end
@@ -34,106 +34,109 @@ uses_mocha "Plugin Loader Tests" do
@configuration.plugin_locators = [locator_class_1, locator_class_2]
assert_equal [:a, :b, :c, :d, :e, :f], @loader.send(:locate_plugins)
end
-
+
def test_should_memoize_the_result_of_locate_plugins_as_all_plugins
plugin_list = [:a, :b, :c]
@loader.expects(:locate_plugins).once.returns(plugin_list)
assert_equal plugin_list, @loader.all_plugins
assert_equal plugin_list, @loader.all_plugins # ensuring that locate_plugins isn't called again
end
-
+
def test_should_return_empty_array_if_configuration_plugins_is_empty
@configuration.plugins = []
assert_equal [], @loader.plugins
end
-
+
def test_should_find_all_availble_plugins_and_return_as_all_plugins
- assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.all_plugins.reverse, @failure_tip
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.all_plugins.reverse, @failure_tip
end
def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_untouched
- assert_plugins [:plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
end
-
+
def test_should_return_all_plugins_as_plugins_when_registered_plugin_list_is_nil
@configuration.plugins = nil
- assert_plugins [:plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
end
def test_should_return_specific_plugins_named_in_config_plugins_array_if_set
- plugin_names = [:stubby]
+ plugin_names = [:acts_as_chunky_bacon, :stubby]
only_load_the_following_plugins! plugin_names
assert_plugins plugin_names, @loader.plugins
end
-
+
def test_should_respect_the_order_of_plugins_given_in_configuration
- plugin_names = [:stubby]
+ plugin_names = [:stubby, :acts_as_chunky_bacon]
only_load_the_following_plugins! plugin_names
- assert_plugins plugin_names, @loader.plugins
+ assert_plugins plugin_names, @loader.plugins
end
-
+
def test_should_load_all_plugins_in_natural_order_when_all_is_used
only_load_the_following_plugins! [:all]
- assert_plugins [:plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
+ assert_plugins [:a, :acts_as_chunky_bacon, :plugin_with_no_lib_dir, :stubby], @loader.plugins, @failure_tip
end
-
+
def test_should_load_specified_plugins_in_order_and_then_all_remaining_plugins_when_all_is_used
- only_load_the_following_plugins! [:stubby, :all]
- assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon, :all]
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip
end
-
+
def test_should_be_able_to_specify_loading_of_plugins_loaded_after_all
- only_load_the_following_plugins! [:stubby, :all]
- assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip
+ only_load_the_following_plugins! [:stubby, :all, :acts_as_chunky_bacon]
+ assert_plugins [:stubby, :a, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @loader.plugins, @failure_tip
end
def test_should_accept_plugin_names_given_as_strings
- only_load_the_following_plugins! ['stubby', :plugin_with_no_lib_dir]
- assert_plugins [:stubby, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip
+ only_load_the_following_plugins! ['stubby', 'acts_as_chunky_bacon', :a, :plugin_with_no_lib_dir]
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :plugin_with_no_lib_dir], @loader.plugins, @failure_tip
end
-
+
def test_should_add_plugin_load_paths_to_global_LOAD_PATH_array
- only_load_the_following_plugins! [:stubby]
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
stubbed_application_lib_index_in_LOAD_PATHS = 5
@loader.stubs(:application_lib_index).returns(stubbed_application_lib_index_in_LOAD_PATHS)
-
+
@loader.add_plugin_load_paths
-
+
assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/stubby'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS
- end
-
+ assert $LOAD_PATH.index(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) >= stubbed_application_lib_index_in_LOAD_PATHS
+ end
+
def test_should_add_plugin_load_paths_to_Dependencies_load_paths
- only_load_the_following_plugins! [:stubby]
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
@loader.add_plugin_load_paths
-
+
assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
+ assert Dependencies.load_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
end
-
+
def test_should_add_plugin_load_paths_to_Dependencies_load_once_paths
- only_load_the_following_plugins! [:stubby]
+ only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
@loader.add_plugin_load_paths
-
+
assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/stubby'), 'lib'))
+ assert Dependencies.load_once_paths.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib'))
end
-
+
def test_should_add_all_load_paths_from_a_plugin_to_LOAD_PATH_array
plugin_load_paths = ["a", "b"]
plugin = stub(:load_paths => plugin_load_paths)
@loader.stubs(:plugins).returns([plugin])
-
+
@loader.add_plugin_load_paths
-
+
plugin_load_paths.each { |path| assert $LOAD_PATH.include?(path) }
end
-
+
private
-
+
def reset_load_path!
$LOAD_PATH.clear
- ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path }
+ ORIGINAL_LOAD_PATH.each { |path| $LOAD_PATH << path }
end
end
-
+
end
diff --git a/railties/test/plugin_locator_test.rb b/railties/test/plugin_locator_test.rb
index a7a76e1cd0..5f1dd991ea 100644
--- a/railties/test/plugin_locator_test.rb
+++ b/railties/test/plugin_locator_test.rb
@@ -3,13 +3,13 @@ require 'plugin_test_helper'
uses_mocha "Plugin Locator Tests" do
class PluginLocatorTest < Test::Unit::TestCase
-
+
def test_should_require_subclasses_to_implement_the_plugins_method
assert_raises(RuntimeError) do
Rails::Plugin::Locator.new(nil).plugins
end
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])
@@ -17,12 +17,12 @@ uses_mocha "Plugin Locator Tests" do
plugin_consumer.expects(:consume).with(:a)
plugin_consumer.expects(:consume).with(:b)
plugin_consumer.expects(:consume).with(:c)
-
+
locator.each do |plugin|
plugin_consumer.consume(plugin)
end
end
-
+
end
@@ -39,22 +39,25 @@ uses_mocha "Plugin Locator Tests" do
end
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)
+ assert_kind_of Rails::Plugin, @locator.send(:create_plugin, @valid_plugin_path)
end
-
+
def test_should_return_nil_when_calling_create_plugin_with_an_invalid_plugin_directory
- assert_nil @locator.send(:create_plugin, @empty_plugin_path)
+ assert_nil @locator.send(:create_plugin, @empty_plugin_path)
end
-
+
def test_should_return_all_plugins_found_under_the_set_plugin_paths
- assert_equal ["plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
+ assert_equal ["a", "acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
end
-
+
def test_should_find_plugins_only_under_the_plugin_paths_set_in_configuration
@configuration.plugin_paths = [File.join(plugin_fixture_root_path, "default")]
- assert_equal ["plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
+ assert_equal ["acts_as_chunky_bacon", "plugin_with_no_lib_dir", "stubby"].sort, @locator.plugins.map(&:name).sort
+
+ @configuration.plugin_paths = [File.join(plugin_fixture_root_path, "alternate")]
+ assert_equal ["a"], @locator.plugins.map(&:name)
end
-
+
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