Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ensure initialize_database_middleware doesn't use ActionController if…

… action_controller framework is not enabled [#2680 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit 0d9e904da35b41c8796b026d63675d4733505c91 1 parent 6ef329d
@calavera calavera authored josh committed
Showing with 23 additions and 6 deletions.
  1. +4 −2 railties/lib/initializer.rb
  2. +19 −4 railties/test/initializer_test.rb
View
6 railties/lib/initializer.rb
@@ -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
@@ -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
@@ -1129,3 +1130,4 @@ def find_pair(key)
return false
end
end
+
View
23 railties/test/initializer_test.rb
@@ -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"),
@@ -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
@@ -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
+
Please sign in to comment.
Something went wrong with that request. Please try again.