diff options
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/abstract_unit.rb | 3 | ||||
-rw-r--r-- | railties/test/initializer_test.rb | 57 |
2 files changed, 50 insertions, 10 deletions
diff --git a/railties/test/abstract_unit.rb b/railties/test/abstract_unit.rb index a950fc8b7e..0775b3ff55 100644 --- a/railties/test/abstract_unit.rb +++ b/railties/test/abstract_unit.rb @@ -1,4 +1,5 @@ $:.unshift File.dirname(__FILE__) + "/../../activesupport/lib" +$:.unshift File.dirname(__FILE__) + "/../../activerecord/lib" $:.unshift File.dirname(__FILE__) + "/../../actionpack/lib" $:.unshift File.dirname(__FILE__) + "/../lib" $:.unshift File.dirname(__FILE__) + "/../builtin/rails_info" @@ -25,4 +26,4 @@ def uses_gem(gem_name, test_name, version = '> 0') yield rescue LoadError $stderr.puts "Skipping #{test_name} tests. `gem install #{gem_name}` and try again." -end +end
\ No newline at end of file diff --git a/railties/test/initializer_test.rb b/railties/test/initializer_test.rb index eb9ec750da..2c448f6dbd 100644 --- a/railties/test/initializer_test.rb +++ b/railties/test/initializer_test.rb @@ -1,6 +1,9 @@ require 'abstract_unit' require 'initializer' +require 'action_view' +require 'active_record' + # Mocks out the configuration module Rails def self.configuration @@ -26,7 +29,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 @@ -268,7 +270,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 +289,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 +299,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 +307,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 +324,46 @@ 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_database_middleware_doesnt_perform_anything_when_active_record_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 RailsRootTest < Test::Unit::TestCase def test_rails_dot_root_equals_rails_root assert_equal RAILS_ROOT, Rails.root.to_s @@ -333,4 +372,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 |