aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test/initializer_test.rb
diff options
context:
space:
mode:
Diffstat (limited to 'railties/test/initializer_test.rb')
-rw-r--r--railties/test/initializer_test.rb77
1 files changed, 38 insertions, 39 deletions
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb
index 987a5ada86..5caa5858a4 100644
--- a/railties/test/initializer_test.rb
+++ b/railties/test/initializer_test.rb
@@ -38,14 +38,15 @@ class Initializer_eager_loading_Test < Test::Unit::TestCase
@config.cache_classes = true
@config.load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")]
@config.eager_load_paths = [File.expand_path(File.dirname(__FILE__) + "/fixtures/eager")]
- @initializer = Rails::Initializer.new(@config)
- @initializer.set_load_path
- @initializer.set_autoload_paths
+ @initializer = Rails::Initializer.default
+ @initializer.config = @config
+ @initializer.run(:set_load_path)
+ @initializer.run(:set_autoload_paths)
end
def test_eager_loading_loads_parent_classes_before_children
assert_nothing_raised do
- @initializer.load_application_classes
+ @initializer.run(:load_application_classes)
end
end
end
@@ -62,7 +63,7 @@ class Initializer_after_initialize_with_blocks_environment_Test < Test::Unit::Te
assert_nil $test_after_initialize_block1
assert_nil $test_after_initialize_block2
- Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true)
+ config.expects(:gems_dependencies_loaded).returns(true)
Rails::Initializer.run(:after_initialize, config)
end
@@ -92,7 +93,7 @@ class Initializer_after_initialize_with_no_block_environment_Test < Test::Unit::
end
assert_nil $test_after_initialize_block1
- Rails::Initializer.any_instance.expects(:gems_dependencies_loaded).returns(true)
+ config.expects(:gems_dependencies_loaded).returns(true)
Rails::Initializer.run(:after_initialize, config)
end
@@ -114,68 +115,65 @@ class ConfigurationFrameworkPathsTests < Test::Unit::TestCase
def setup
@config = Rails::Configuration.new
@config.frameworks.clear
+ @initializer = Rails::Initializer.default
+ @initializer.config = @config
File.stubs(:directory?).returns(true)
- @config.stubs(:framework_root_path).returns('')
+ Rails::Initializer.run(:set_root_path, @config)
end
def test_minimal
- expected = %w(
- /railties
- /railties/lib
- /activesupport/lib
- )
- assert_equal expected, @config.framework_paths
+ expected = %w(railties railties/lib activesupport/lib)
+ assert_equal expected.map {|e| "#{@config.framework_root_path}/#{e}"}, @config.framework_paths
end
def test_actioncontroller_or_actionview_add_actionpack
@config.frameworks << :action_controller
- assert_framework_path '/actionpack/lib'
+ assert_framework_path "actionpack/lib"
@config.frameworks = [:action_view]
- assert_framework_path '/actionpack/lib'
+ assert_framework_path 'actionpack/lib'
end
def test_paths_for_ar_ares_and_mailer
[:active_record, :action_mailer, :active_resource, :action_web_service].each do |framework|
@config.frameworks = [framework]
- assert_framework_path "/#{framework.to_s.gsub('_', '')}/lib"
+ assert_framework_path "#{framework.to_s.gsub('_', '')}/lib"
end
end
def test_unknown_framework_raises_error
@config.frameworks << :action_foo
- initializer = Rails::Initializer.new @config
- initializer.expects(:require).raises(LoadError)
+
+ Class.any_instance.expects(:require).raises(LoadError)
assert_raise RuntimeError do
- initializer.send :require_frameworks
+ @initializer.run(:require_frameworks)
end
end
def test_action_mailer_load_paths_set_only_if_action_mailer_in_use
@config.frameworks = [:action_controller]
- initializer = Rails::Initializer.new @config
- initializer.send :require_frameworks
+ @initializer.config = @config
+ @initializer.run :require_frameworks
assert_nothing_raised NameError do
- initializer.send :load_view_paths
+ @initializer.run :load_view_paths
end
end
def test_action_controller_load_paths_set_only_if_action_controller_in_use
@config.frameworks = []
- initializer = Rails::Initializer.new @config
- initializer.send :require_frameworks
+ @initializer.run :require_frameworks
assert_nothing_raised NameError do
- initializer.send :load_view_paths
+ @initializer.run :load_view_paths
end
end
protected
def assert_framework_path(path)
- assert @config.framework_paths.include?(path),
+ assert @config.framework_paths.include?("#{@config.framework_root_path}/#{path}"),
"<#{path.inspect}> not found among <#{@config.framework_paths.inspect}>"
end
end
@@ -187,28 +185,29 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
@configuration = Rails::Configuration.new
@configuration.frameworks -= [:action_mailer]
@configuration.plugin_paths << plugin_fixture_root_path
- @initializer = Rails::Initializer.new(@configuration)
+ @initializer = Rails::Initializer.default
+ @initializer.config = @configuration
@valid_plugin_path = plugin_fixture_path('default/stubby')
@empty_plugin_path = plugin_fixture_path('default/empty')
end
def test_no_plugins_are_loaded_if_the_configuration_has_an_empty_plugin_list
only_load_the_following_plugins! []
- @initializer.load_plugins
- assert_equal [], @initializer.loaded_plugins
+ @initializer.run :load_plugins
+ assert_equal [], @configuration.loaded_plugins
end
def test_only_the_specified_plugins_are_located_in_the_order_listed
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
+ assert_plugins plugin_names, @configuration.loaded_plugins
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"
load_plugins!
- assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @initializer.loaded_plugins, failure_tip
+ assert_plugins [:a, :acts_as_chunky_bacon, :engine, :gemlike, :plugin_with_no_lib_dir, :stubby], @configuration.loaded_plugins, failure_tip
end
def test_all_plugins_loaded_when_all_is_used
@@ -216,7 +215,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
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, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @initializer.loaded_plugins, failure_tip
+ assert_plugins [:stubby, :acts_as_chunky_bacon, :a, :engine, :gemlike, :plugin_with_no_lib_dir], @configuration.loaded_plugins, failure_tip
end
def test_all_plugins_loaded_after_all
@@ -224,7 +223,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
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, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @initializer.loaded_plugins, failure_tip
+ assert_plugins [:stubby, :a, :engine, :gemlike, :plugin_with_no_lib_dir, :acts_as_chunky_bacon], @configuration.loaded_plugins, failure_tip
end
def test_plugin_names_may_be_strings
@@ -232,7 +231,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
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_names, @initializer.loaded_plugins, failure_tip
+ assert_plugins plugin_names, @configuration.loaded_plugins, failure_tip
end
def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error
@@ -251,7 +250,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
flunk "Expected a LoadError but did not get one"
rescue LoadError => e
failure_tip = "It's likely someone renamed or deleted plugin fixtures without updating this test"
- assert_plugins valid_plugin_names, @initializer.loaded_plugins, failure_tip
+ assert_plugins valid_plugin_names, @configuration.loaded_plugins, failure_tip
invalid_plugin_names.each do |plugin|
assert_match(/#{plugin.to_s}/, e.message, "LoadError message should mention plugin '#{plugin}'")
end
@@ -265,7 +264,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
def test_should_ensure_all_loaded_plugins_load_paths_are_added_to_the_load_path
only_load_the_following_plugins! [:stubby, :acts_as_chunky_bacon]
- @initializer.add_plugin_load_paths
+ @initializer.run(: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'))
@@ -274,8 +273,8 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase
private
def load_plugins!
- @initializer.add_plugin_load_paths
- @initializer.load_plugins
+ @initializer.run(:add_plugin_load_paths)
+ @initializer.run(:load_plugins)
end
end
@@ -315,7 +314,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase
File.expand_path(File.dirname(__FILE__) + "/../../activemodel/lib/active_model/locale/en.yml"),
File.expand_path(File.dirname(__FILE__) + "/../../activerecord/lib/active_record/locale/en.yml"),
"my/test/locale.yml",
- "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /^\./ ? File.expand_path(path) : path }
+ "my/other/locale.yml" ], I18n.load_path.collect { |path| path =~ /\.\./ ? File.expand_path(path) : path }
end
def test_setting_another_default_locale