summary refs log tree commit
diff options
context:
space:
mode:
authorRafael Mendonça França <rafael.franca@plataformatec.com.br>2014-07-18 15:27:36 -0300
committerRafael Mendonça França <rafael.franca@plataformatec.com.br>2014-07-18 15:33:45 -0300
commitf667205a8f45cf11c22d8e6eb50d09c8df3bef07 (patch)
tree36f713fd6d93a8c911bcf2cc86c07594ec3feebd
parent4a02eceb729d6901cec85e74cc0296cc9a08017f (diff)
downloadrack-f667205a8f45cf11c22d8e6eb50d09c8df3bef07.tar.gz
default_middleware_by_environment should always returns empty array for unknown keys
The current behaviour break rails server for any environment different
of development.

This behaviour was removed at 704be37e with a warning that if this
behavior is supported tests need to be added. The tests are already
there and they were not failing because "none" environment were added to
the hash. This environment is not a valid environment and it is on the
tests exactly to assert the behaviour that
default_middleware_by_environment always return an empty array for
unknown keys.
-rw-r--r--lib/rack/server.rb34
-rw-r--r--test/spec_server.rb7
2 files changed, 23 insertions, 18 deletions
diff --git a/lib/rack/server.rb b/lib/rack/server.rb
index d51a95eb..d2f0b954 100644
--- a/lib/rack/server.rb
+++ b/lib/rack/server.rb
@@ -213,23 +213,23 @@ module Rack
       end
 
       def default_middleware_by_environment
-        {
-          "deployment" => [
-            [Rack::ContentLength],
-            [Rack::Chunked],
-            logging_middleware,
-            [Rack::TempfileReaper]
-          ],
-          "development" => [
-            [Rack::ContentLength],
-            [Rack::Chunked],
-            logging_middleware,
-            [Rack::ShowExceptions],
-            [Rack::Lint],
-            [Rack::TempfileReaper]
-          ],
-          "none" => []
-        }
+        m = Hash.new {|h,k| h[k] = []}
+        m["deployment"] = [
+          [Rack::ContentLength],
+          [Rack::Chunked],
+          logging_middleware,
+          [Rack::TempfileReaper]
+        ]
+        m["development"] = [
+          [Rack::ContentLength],
+          [Rack::Chunked],
+          logging_middleware,
+          [Rack::ShowExceptions],
+          [Rack::Lint],
+          [Rack::TempfileReaper]
+        ]
+
+        m
       end
 
       # Aliased for backwards-compatibility
diff --git a/test/spec_server.rb b/test/spec_server.rb
index 9a81875a..08530dfa 100644
--- a/test/spec_server.rb
+++ b/test/spec_server.rb
@@ -40,6 +40,11 @@ describe Rack::Server do
     server.default_middleware_by_environment['none'].flatten.should.not.include(Rack::ShowExceptions)
   end
 
+  should "always return an empty array for unknown environments" do
+    server = Rack::Server.new(:app => 'foo')
+    server.default_middleware_by_environment['production'].should.equal []
+  end
+
   should "include Rack::TempfileReaper in deployment environment" do
     server = Rack::Server.new(:app => 'foo')
     server.middleware['deployment'].flatten.should.include(Rack::TempfileReaper)
@@ -72,7 +77,7 @@ describe Rack::Server do
     FileUtils.rm pidfile
     server = Rack::Server.new(
       :app         => app,
-      :environment => 'none',
+      :environment => 'production',
       :pid         => pidfile,
       :Port        => TCPServer.open('127.0.0.1', 0){|s| s.addr[1] },
       :Host        => '127.0.0.1',