Skip to content
Browse files

Move default middleware stack into initializer

  • Loading branch information...
1 parent 71b33ec commit 1f7270057596592946a877cd029d95760ba3e5ee @josh josh committed Sep 26, 2009
View
5 actionpack/lib/action_controller/dispatch/dispatcher.rb
@@ -11,10 +11,7 @@ class Dispatcher
self.router = Routing::Routes
cattr_accessor :middleware
- self.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
- middlewares = File.join(File.dirname(__FILE__), "middlewares.rb")
- middleware.instance_eval(File.read(middlewares), middlewares, 1)
- end
+ self.middleware = ActionDispatch::MiddlewareStack.new
class << self
def define_dispatcher_callbacks(cache_classes)
View
16 actionpack/lib/action_controller/dispatch/middlewares.rb
@@ -1,16 +0,0 @@
-use "Rack::Lock", :if => lambda {
- !ActionController::Base.allow_concurrency
-}
-
-use "ActionDispatch::ShowExceptions", lambda { ActionController::Base.consider_all_requests_local }
-use "ActionDispatch::Callbacks", lambda { ActionController::Dispatcher.prepare_each_request }
-
-# TODO: Redirect global exceptions somewhere?
-# use "ActionDispatch::Rescue"
-
-use lambda { ActionController::Base.session_store },
- lambda { ActionController::Base.session_options }
-
-use "ActionDispatch::ParamsParser"
-use "Rack::MethodOverride"
-use "Rack::Head"
View
13 actionpack/test/abstract_unit.rb
@@ -52,6 +52,13 @@
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
+ActionController::Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
+ middleware.use "ActionDispatch::ShowExceptions"
+ middleware.use "ActionDispatch::Callbacks"
+ middleware.use "ActionDispatch::ParamsParser"
+ middleware.use "Rack::Head"
+end
+
module ActionView
class TestCase
setup do
@@ -114,12 +121,6 @@ class ::ApplicationController < ActionController::Base
end
module ActionController
- Base.session = {
- :key => '_testing_session',
- :secret => '8273f16463985e2b3747dc25e30f2528'
- }
- Base.session_store = nil
-
class << Routing
def possible_controllers
@@possible_controllers ||= []
View
4 actionpack/test/controller/dispatcher_test.rb
@@ -83,10 +83,6 @@ def test_to_prepare_with_identifier_replaces
def dispatch(cache_classes = true)
ActionController::Dispatcher.prepare_each_request = false
Dispatcher.define_dispatcher_callbacks(cache_classes)
- Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
- middlewares = File.expand_path(File.join(File.dirname(__FILE__), "../../lib/action_controller/dispatch/middlewares.rb"))
- middleware.instance_eval(File.read(middlewares))
- end
@dispatcher ||= Dispatcher.new
@dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false})
View
3 actionpack/test/dispatch/session/cookie_store_test.rb
@@ -5,9 +5,6 @@ class CookieStoreTest < ActionController::IntegrationTest
SessionKey = '_myapp_session'
SessionSecret = 'b3c631c314c0bbca50c1b2843150fe33'
- # Make sure Session middleware doesnt get included in the middleware stack
- ActionController::Base.session_store = nil
-
Verifier = ActiveSupport::MessageVerifier.new(SessionSecret, 'SHA1')
SignedBar = Verifier.generate(:foo => "bar", :session_id => ActiveSupport::SecureRandom.hex(16))
View
2 railties/lib/rails/console_app.rb
@@ -25,7 +25,7 @@ def new_session
#reloads the environment
def reload!
puts "Reloading..."
- ActionController::Dispatcher.new
+ ActionDispatch::Callbacks.new(lambda {}, true)
ActionController::Dispatcher.router.reload
true
end
View
14 railties/lib/rails/initializer.rb
@@ -272,7 +272,19 @@ def self.run(initializer = nil, config = nil)
# Include middleware to serve up static assets
Initializer.default.add :initialize_static_server do
if configuration.frameworks.include?(:action_controller) && configuration.serve_static_assets
- configuration.middleware.insert(0, ActionDispatch::Static, Rails.public_path)
+ configuration.middleware.use(ActionDispatch::Static, Rails.public_path)
+ end
+ end
+
+ Initializer.default.add :initialize_middleware_stack do
+ if configuration.frameworks.include?(:action_controller)
+ configuration.middleware.use(::Rack::Lock) unless ActionController::Base.allow_concurrency
+ configuration.middleware.use(ActionDispatch::ShowExceptions, ActionController::Base.consider_all_requests_local)
+ configuration.middleware.use(ActionDispatch::Callbacks, ActionController::Dispatcher.prepare_each_request)
+ configuration.middleware.use(lambda { ActionController::Base.session_store }, lambda { ActionController::Base.session_options })
+ configuration.middleware.use(ActionDispatch::ParamsParser)
+ configuration.middleware.use(::Rack::MethodOverride)
+ configuration.middleware.use(::Rack::Head)
end
end
View
5 railties/test/console_app_test.rb
@@ -2,11 +2,6 @@
require 'action_controller' # console_app uses 'action_controller/integration'
-unless defined? ApplicationController
- class ApplicationController < ActionController::Base; end
- ActionController::Base.session_store = nil
-end
-
require 'rails/dispatcher'
require 'rails/console_app'

0 comments on commit 1f72700

Please sign in to comment.
Something went wrong with that request. Please try again.