Skip to content

Commit

Permalink
ActiveRecord middlewares should be inserted before AD::Cascade [#4493
Browse files Browse the repository at this point in the history
…state:resolved].
  • Loading branch information
josevalim committed Apr 29, 2010
1 parent e9a9ef0 commit 3dfcb56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 11 deletions.
9 changes: 2 additions & 7 deletions activerecord/lib/active_record/railtie.rb
Expand Up @@ -61,13 +61,8 @@ class Railtie < Rails::Railtie
# 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|
Expand Down
2 changes: 1 addition & 1 deletion railties/lib/rails/application/configuration.rb
Expand Up @@ -143,7 +143,7 @@ def default_middleware_stack
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')
Expand Down
6 changes: 3 additions & 3 deletions railties/test/application/middleware_test.rb
Expand Up @@ -27,14 +27,14 @@ def app
"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

Expand Down

0 comments on commit 3dfcb56

Please sign in to comment.