aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activerecord/lib/active_record/identity_map.rb5
-rw-r--r--activerecord/lib/active_record/railtie.rb8
-rw-r--r--railties/test/application/middleware_test.rb5
3 files changed, 13 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/identity_map.rb b/activerecord/lib/active_record/identity_map.rb
index fe448abfdf..30a2a1eb0f 100644
--- a/activerecord/lib/active_record/identity_map.rb
+++ b/activerecord/lib/active_record/identity_map.rb
@@ -98,8 +98,9 @@ module ActiveRecord
end
def call(env)
- ActiveRecord::IdentityMap.enabled? ?
- ActiveRecord::IdentityMap.use { @app.call(env) } : @app.call(env)
+ ActiveRecord::IdentityMap.use do
+ @app.call(env)
+ end
end
end
end
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index 5d0424a543..6afa2d4cf3 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -22,9 +22,6 @@ module ActiveRecord
config.app_middleware.insert_after "::ActionDispatch::Callbacks",
"ActiveRecord::ConnectionAdapters::ConnectionManagement"
- config.app_middleware.insert_after "::ActionDispatch::Callbacks",
- "ActiveRecord::IdentityMap::Middleware"
-
rake_tasks do
load "active_record/railties/databases.rake"
end
@@ -81,6 +78,11 @@ module ActiveRecord
end
end
+ initializer "active_record.identity_map" do |app|
+ config.app_middleware.insert_after "::ActionDispatch::Callbacks",
+ "ActiveRecord::IdentityMap::Middleware" if ActiveRecord::IdentityMap.enabled?
+ end
+
config.after_initialize do
ActiveSupport.on_load(:active_record) do
instantiate_observers
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb
index 9820a92918..f74fa594d9 100644
--- a/railties/test/application/middleware_test.rb
+++ b/railties/test/application/middleware_test.rb
@@ -107,6 +107,11 @@ module ApplicationTests
assert_equal "Rack::Runtime", middleware.fourth
end
+ test "identity map is inserted" do
+ boot!
+ assert_equal "ActiveRecord::IdentityMap::Middleware", middleware[9]
+ end
+
test "insert middleware before" do
add_to_config "config.middleware.insert_before ActionDispatch::Static, Rack::Config"
boot!