diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-03-10 00:33:32 +0000 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-03-10 00:33:32 +0000 |
commit | 1ab84247ca4b80afbd82afe7539b3449636344c4 (patch) | |
tree | 9ca5e3bee3a07b68c9d900ff129b69bc740405c2 /railties/test/initializer_test.rb | |
parent | b6fb79c531a0079274f7b459302e6290c9183f28 (diff) | |
parent | 4458edc882b229ea44602da20a6440a6f233f1c8 (diff) | |
download | rails-1ab84247ca4b80afbd82afe7539b3449636344c4.tar.gz rails-1ab84247ca4b80afbd82afe7539b3449636344c4.tar.bz2 rails-1ab84247ca4b80afbd82afe7539b3449636344c4.zip |
Merge commit 'mainstream/master'
Conflicts:
railties/guides/files/stylesheets/main.css
railties/guides/rails_guides/generator.rb
railties/guides/source/index.erb.textile
Diffstat (limited to 'railties/test/initializer_test.rb')
-rw-r--r-- | railties/test/initializer_test.rb | 83 |
1 files changed, 73 insertions, 10 deletions
diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index eb9ec750da..561f7b8b54 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -1,6 +1,10 @@ require 'abstract_unit' require 'initializer' +require 'action_view' +require 'action_mailer' +require 'active_record' + # Mocks out the configuration module Rails def self.configuration @@ -26,7 +30,6 @@ class Initializer_load_environment_Test < Test::Unit::TestCase ensure $initialize_test_set_from_env = nil end - end class Initializer_eager_loading_Test < Test::Unit::TestCase @@ -234,7 +237,7 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase def test_registering_a_plugin_name_that_does_not_exist_raises_a_load_error only_load_the_following_plugins! [:stubby, :acts_as_a_non_existant_plugin] - assert_raises(LoadError) do + assert_raise(LoadError) do load_plugins! end end @@ -268,7 +271,6 @@ class InitializerPluginLoadingTests < Test::Unit::TestCase assert $LOAD_PATH.include?(File.join(plugin_fixture_path('default/acts/acts_as_chunky_bacon'), 'lib')) end - private def load_plugins! @@ -288,7 +290,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) assert_equal [ "my/test/locale.yml" ], Rails::Configuration.new.i18n.load_path end - + def test_config_defaults_should_be_added_with_config_settings File.stubs(:exist?).returns(true) Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) @@ -298,7 +300,7 @@ class InitializerSetupI18nTests < Test::Unit::TestCase assert_equal [ "my/test/locale.yml", "my/other/locale.yml" ], config.i18n.load_path end - + def test_config_defaults_and_settings_should_be_added_to_i18n_defaults File.stubs(:exist?).returns(true) Dir.stubs(:[]).returns([ "my/test/locale.yml" ]) @@ -306,17 +308,15 @@ class InitializerSetupI18nTests < Test::Unit::TestCase config = Rails::Configuration.new config.i18n.load_path << "my/other/locale.yml" - # To bring in AV's i18n load path. - require 'action_view' - Rails::Initializer.run(:initialize_i18n, config) assert_equal [ File.expand_path(File.dirname(__FILE__) + "/../../activesupport/lib/active_support/locale/en.yml"), File.expand_path(File.dirname(__FILE__) + "/../../actionpack/lib/action_view/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 } end - + def test_setting_another_default_locale config = Rails::Configuration.new config.i18n.default_locale = :de @@ -325,6 +325,69 @@ class InitializerSetupI18nTests < Test::Unit::TestCase end end +class InitializerDatabaseMiddlewareTest < Test::Unit::TestCase + def setup + @config = Rails::Configuration.new + @config.frameworks = [:active_record, :action_controller, :action_view] + end + + def test_initialize_database_middleware_doesnt_perform_anything_when_active_record_not_in_frameworks + @config.frameworks.clear + @config.expects(:middleware).never + Rails::Initializer.run(:initialize_database_middleware, @config) + end + + def test_database_middleware_initializes_when_session_store_is_active_record + store = ActionController::Base.session_store + ActionController::Base.session_store = ActiveRecord::SessionStore + + @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement) + @config.middleware.expects(:insert_before).with(:"ActiveRecord::SessionStore", ActiveRecord::QueryCache) + + Rails::Initializer.run(:initialize_database_middleware, @config) + ensure + ActionController::Base.session_store = store + end + + def test_database_middleware_doesnt_initialize_when_session_store_is_not_active_record + store = ActionController::Base.session_store + ActionController::Base.session_store = ActionController::Session::CookieStore + + # Define the class, so we don't have to actually make it load + eval("class ActiveRecord::ConnectionAdapters::ConnectionManagement; end") + + @config.middleware.expects(:use).with(ActiveRecord::ConnectionAdapters::ConnectionManagement) + @config.middleware.expects(:use).with(ActiveRecord::QueryCache) + + Rails::Initializer.run(:initialize_database_middleware, @config) + ensure + ActionController::Base.session_store = store + end +end + +class InitializerViewPathsTest < Test::Unit::TestCase + def setup + @config = Rails::Configuration.new + @config.frameworks = [:action_view, :action_controller, :action_mailer] + + ActionController::Base.stubs(:view_paths).returns(stub) + ActionMailer::Base.stubs(:view_paths).returns(stub) + end + + def test_load_view_paths_doesnt_perform_anything_when_action_view_not_in_frameworks + @config.frameworks -= [:action_view] + ActionController::Base.view_paths.expects(:load!).never + ActionMailer::Base.view_paths.expects(:load!).never + Rails::Initializer.run(:load_view_paths, @config) + end + + def test_load_view_paths_loads_view_paths + ActionController::Base.view_paths.expects(:load!) + ActionMailer::Base.view_paths.expects(:load!) + Rails::Initializer.run(:load_view_paths, @config) + end +end + class RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_equals_rails_root assert_equal RAILS_ROOT, Rails.root.to_s @@ -333,4 +396,4 @@ class RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_should_be_a_pathname assert_equal File.join(RAILS_ROOT, 'app', 'controllers'), Rails.root.join('app', 'controllers').to_s end -end +end
\ No newline at end of file |