diff --git a/railties/lib/rails/application.rb b/railties/lib/rails/application.rb index b923fedab7b73dd51d87a3d19fa9e294929fb09e..0e85e6d1d55553d8bfb90bf00b54ffa30c4de012 100644 --- a/railties/lib/rails/application.rb +++ b/railties/lib/rails/application.rb @@ -147,9 +147,11 @@ def config def default_middleware_stack ActionDispatch::MiddlewareStack.new.tap do |middleware| - require "action_dispatch/http/rack_cache" if config.action_dispatch.rack_cache + rack_cache = config.action_controller.perform_caching && config.action_dispatch.rack_cache - middleware.use ::Rack::Cache, config.action_dispatch.rack_cache if config.action_dispatch.rack_cache + require "action_dispatch/http/rack_cache" if rack_cache + + middleware.use ::Rack::Cache, rack_cache if rack_cache middleware.use ::ActionDispatch::Static, config.static_asset_paths if config.serve_static_assets middleware.use ::Rack::Lock if !config.allow_concurrency middleware.use ::Rack::Runtime diff --git a/railties/test/application/middleware/cache_test.rb b/railties/test/application/middleware/cache_test.rb index 655f9bcd55d4e6f807b1e6fa6c0cd81354ff3cc1..5675cebfd97ade300ab8d3c4790619f0cab63d7b 100644 --- a/railties/test/application/middleware/cache_test.rb +++ b/railties/test/application/middleware/cache_test.rb @@ -24,7 +24,7 @@ def app(env = "production") end def simple_controller - controller :foo, <<-RUBY + controller :expires, <<-RUBY class ExpiresController < ApplicationController def expires_header expires_in 10, :public => !params[:private] @@ -55,6 +55,20 @@ def render_conditionally(headers) RUBY end + def test_cache_is_disabled_in_dev_mode + simple_controller + app("development") + + get "/expires/expires_header" + assert_nil last_response.headers['X-Rack-Cache'] + + body = last_response.body + + get "/expires/expires_header" + assert_nil last_response.headers['X-Rack-Cache'] + assert_not_equal body, last_response.body + end + def test_cache_works_with_expires simple_controller diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 0ce6d482a047b46723077cd4ffe96a9066565b70..f9b594eb33b314e4398d6a5f2b91db6bf2ac029f 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -18,6 +18,33 @@ def app test "default middleware stack" do boot! + assert_equal [ + "ActionDispatch::Static", + "Rack::Lock", + "ActiveSupport::Cache::Strategy::LocalCache", + "Rack::Runtime", + "Rails::Rack::Logger", + "ActionDispatch::ShowExceptions", + "ActionDispatch::RemoteIp", + "Rack::Sendfile", + "ActionDispatch::Callbacks", + "ActiveRecord::ConnectionAdapters::ConnectionManagement", + "ActiveRecord::QueryCache", + "ActionDispatch::Cookies", + "ActionDispatch::Session::CookieStore", + "ActionDispatch::Flash", + "ActionDispatch::ParamsParser", + "Rack::MethodOverride", + "ActionDispatch::Head", + "ActionDispatch::BestStandardsSupport" + ], middleware + end + + test "Rack::Cache is present when action_controller.perform_caching is set" do + add_to_config "config.action_controller.perform_caching = true" + + boot! + assert_equal [ "Rack::Cache", "ActionDispatch::Static", @@ -82,24 +109,24 @@ def app test "insert middleware after" do add_to_config "config.middleware.insert_after ActionDispatch::Static, Rack::Config" boot! - assert_equal "Rack::Config", middleware.third + assert_equal "Rack::Config", middleware.second end test "RAILS_CACHE does not respond to middleware" do add_to_config "config.cache_store = :memory_store" boot! - assert_equal "Rack::Runtime", middleware.fourth + assert_equal "Rack::Runtime", middleware.third end test "RAILS_CACHE does respond to middleware" do boot! - assert_equal "Rack::Runtime", middleware.fifth + assert_equal "Rack::Runtime", middleware.fourth end test "insert middleware before" do add_to_config "config.middleware.insert_before ActionDispatch::Static, Rack::Config" boot! - assert_equal "Rack::Config", middleware.second + assert_equal "Rack::Config", middleware.first end # x_sendfile_header middleware