Make dispatcher instances immutable
This commit is contained in:
parent
4a3afe0b4f
commit
c1b4a5eb56
@ -66,16 +66,21 @@ def cleanup_application
|
||||
define_callbacks :prepare_dispatch, :before_dispatch, :after_dispatch
|
||||
|
||||
def initialize
|
||||
@app = @@middleware.build(lambda { |env| self.dup._call(env) })
|
||||
@app = @@middleware.build(lambda { |env| self._call(env) })
|
||||
freeze
|
||||
end
|
||||
|
||||
def dispatch
|
||||
def call(env)
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
def _call(env)
|
||||
begin
|
||||
run_callbacks :before_dispatch
|
||||
Routing::Routes.call(@env)
|
||||
Routing::Routes.call(env)
|
||||
rescue Exception => exception
|
||||
if controller ||= (::ApplicationController rescue Base)
|
||||
controller.call_with_exception(@env, exception).to_a
|
||||
controller.call_with_exception(env, exception).to_a
|
||||
else
|
||||
raise exception
|
||||
end
|
||||
@ -84,15 +89,6 @@ def dispatch
|
||||
end
|
||||
end
|
||||
|
||||
def call(env)
|
||||
@app.call(env)
|
||||
end
|
||||
|
||||
def _call(env)
|
||||
@env = env
|
||||
dispatch
|
||||
end
|
||||
|
||||
def flush_logger
|
||||
Base.logger.flush
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ def log_failsafe_exception(status, exception); end
|
||||
end
|
||||
|
||||
def test_failsafe_response
|
||||
Dispatcher.any_instance.expects(:dispatch).raises('b00m')
|
||||
Dispatcher.any_instance.expects(:_call).raises('b00m')
|
||||
ActionDispatch::Failsafe.any_instance.expects(:log_failsafe_exception)
|
||||
|
||||
assert_nothing_raised do
|
||||
|
Loading…
Reference in New Issue
Block a user