Skip to content

Commit

Permalink
ensure initialize_database_middleware doesn't use ActionController if…
Browse files Browse the repository at this point in the history
… action_controller framework is not enabled [#2680 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information
calavera authored and josh committed May 27, 2009
1 parent 6ef329d commit 0d9e904
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
6 changes: 4 additions & 2 deletions railties/lib/initializer.rb
Expand Up @@ -445,7 +445,8 @@ def initialize_database

def initialize_database_middleware
if configuration.frameworks.include?(:active_record)
if ActionController::Base.session_store == ActiveRecord::SessionStore
if configuration.frameworks.include?(:action_controller) &&
ActionController::Base.session_store == ActiveRecord::SessionStore
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement
configuration.middleware.insert_before :"ActiveRecord::SessionStore", ActiveRecord::QueryCache
else
Expand Down Expand Up @@ -886,7 +887,7 @@ def set_root_path!

# Enable threaded mode. Allows concurrent requests to controller actions and
# multiple database connections. Also disables automatic dependency loading
# after boot, and disables reloading code on every request, as these are
# after boot, and disables reloading code on every request, as these are
# fundamentally incompatible with thread safety.
def threadsafe!
self.preload_frameworks = true
Expand Down Expand Up @@ -1129,3 +1130,4 @@ def find_pair(key)
return false
end
end

23 changes: 19 additions & 4 deletions railties/test/initializer_test.rb
Expand Up @@ -309,7 +309,7 @@ def test_config_defaults_and_settings_should_be_added_to_i18n_defaults
config.i18n.load_path << "my/other/locale.yml"

Rails::Initializer.run(:initialize_i18n, config)
assert_equal [
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"),
Expand Down Expand Up @@ -363,17 +363,31 @@ def test_database_middleware_doesnt_initialize_when_session_store_is_not_active_
ensure
ActionController::Base.session_store = store
end

def test_ensure_database_middleware_doesnt_use_action_controller_on_initializing
@config.frameworks -= [:action_controller]
store = ActionController::Base.session_store
ActionController::Base.session_store = ActiveRecord::SessionStore

@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
@config.frameworks += [:action_controller]
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
Expand All @@ -390,4 +404,5 @@ def test_rails_dot_root_equals_rails_root
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

0 comments on commit 0d9e904

Please sign in to comment.