From 3dfcb56e4585c8530be6dcc5129ae0c4d16c0dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 29 Apr 2010 13:24:24 +0200 Subject: [PATCH] ActiveRecord middlewares should be inserted before AD::Cascade [#4493 state:resolved]. --- activerecord/lib/active_record/railtie.rb | 9 ++------- railties/lib/rails/application/configuration.rb | 2 +- railties/test/application/middleware_test.rb | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb index f3d21d4969e..898df0a67a0 100644 --- a/activerecord/lib/active_record/railtie.rb +++ b/activerecord/lib/active_record/railtie.rb @@ -61,13 +61,8 @@ module ActiveRecord # Setup database middleware after initializers have run initializer "active_record.initialize_database_middleware", :after => "action_controller.set_configs" do |app| middleware = app.config.middleware - if middleware.include?("ActiveRecord::SessionStore") - middleware.insert_before "ActiveRecord::SessionStore", ActiveRecord::ConnectionAdapters::ConnectionManagement - middleware.insert_before "ActiveRecord::SessionStore", ActiveRecord::QueryCache - else - middleware.use ActiveRecord::ConnectionAdapters::ConnectionManagement - middleware.use ActiveRecord::QueryCache - end + middleware.insert_after "::ActionDispatch::Callbacks", ActiveRecord::QueryCache + middleware.insert_after "::ActionDispatch::Callbacks", ActiveRecord::ConnectionAdapters::ConnectionManagement end initializer "active_record.set_dispatch_hooks", :before => :set_clear_dependencies_hook do |app| diff --git a/railties/lib/rails/application/configuration.rb b/railties/lib/rails/application/configuration.rb index a58f7e90793..77f5eea3c48 100644 --- a/railties/lib/rails/application/configuration.rb +++ b/railties/lib/rails/application/configuration.rb @@ -143,7 +143,7 @@ module Rails middleware.use('::Rack::Runtime') middleware.use('::Rails::Rack::Logger') middleware.use('::ActionDispatch::ShowExceptions', lambda { consider_all_requests_local }, :if => lambda { action_dispatch.show_exceptions }) - middleware.use("::ActionDispatch::RemoteIp", lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies }) + middleware.use('::ActionDispatch::RemoteIp', lambda { action_dispatch.ip_spoofing_check }, lambda { action_dispatch.trusted_proxies }) middleware.use('::Rack::Sendfile', lambda { action_dispatch.x_sendfile_header }) middleware.use('::ActionDispatch::Callbacks', lambda { !cache_classes }) middleware.use('::ActionDispatch::Cookies') diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index e9cddcc65a4..d08f04bddbd 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -27,14 +27,14 @@ module ApplicationTests "ActionDispatch::RemoteIp", "Rack::Sendfile", "ActionDispatch::Callbacks", + "ActiveRecord::ConnectionAdapters::ConnectionManagement", + "ActiveRecord::QueryCache", "ActionDispatch::Cookies", "ActionDispatch::Session::CookieStore", "ActionDispatch::Flash", "ActionDispatch::ParamsParser", "Rack::MethodOverride", - "ActionDispatch::Head", - "ActiveRecord::ConnectionAdapters::ConnectionManagement", - "ActiveRecord::QueryCache" + "ActionDispatch::Head" ], middleware end