diff options
Diffstat (limited to 'railties/test/application/middleware_test.rb')
-rw-r--r-- | railties/test/application/middleware_test.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/railties/test/application/middleware_test.rb b/railties/test/application/middleware_test.rb index 6f14200a14..4703a59326 100644 --- a/railties/test/application/middleware_test.rb +++ b/railties/test/application/middleware_test.rb @@ -11,20 +11,26 @@ module ApplicationTests FileUtils.rm_rf "#{app_path}/config/environments" end + def teardown + teardown_app + end + def app @app ||= Rails.application end test "default middleware stack" do + add_to_config "config.action_dispatch.x_sendfile_header = 'X-Sendfile'" + boot! assert_equal [ - "Rack::ContentLength", "ActionDispatch::Static", "Rack::Lock", "ActiveSupport::Cache::Strategy::LocalCache", "Rack::Runtime", "Rack::MethodOverride", + "ActionDispatch::RequestId", "Rails::Rack::Logger", # must come after Rack::MethodOverride to properly log overridden methods "ActionDispatch::ShowExceptions", "ActionDispatch::RemoteIp", @@ -44,12 +50,18 @@ module ApplicationTests ], middleware end + test "Rack::Sendfile is not included by default" do + boot! + + assert !middleware.include?("Rack::Sendfile"), "Rack::Sendfile is not included in the default stack unless you set config.action_dispatch.x_sendfile_header" + 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", middleware.second + assert_equal "Rack::Cache", middleware.first end test "Rack::SSL is present when force_ssl is set" do @@ -58,6 +70,14 @@ module ApplicationTests assert middleware.include?("Rack::SSL") end + test "Rack::SSL is configured with options when given" do + add_to_config "config.force_ssl = true" + add_to_config "config.ssl_options = { :host => 'example.com' }" + boot! + + assert_equal AppTemplate::Application.middleware.first.args, [{:host => 'example.com'}] + end + test "removing Active Record omits its middleware" do use_frameworks [] boot! @@ -104,7 +124,7 @@ module ApplicationTests end test "insert middleware after" do - add_to_config "config.middleware.insert_after Rack::ContentLength, Rack::Config" + add_to_config "config.middleware.insert_after ActionDispatch::Static, Rack::Config" boot! assert_equal "Rack::Config", middleware.second end @@ -112,12 +132,12 @@ module ApplicationTests 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 "identity map is inserted" do @@ -127,7 +147,7 @@ module ApplicationTests end test "insert middleware before" do - add_to_config "config.middleware.insert_before Rack::ContentLength, Rack::Config" + add_to_config "config.middleware.insert_before ActionDispatch::Static, Rack::Config" boot! assert_equal "Rack::Config", middleware.first end |