aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_dispatch/middleware/reloader.rb23
-rw-r--r--actionpack/test/dispatch/reloader_test.rb25
2 files changed, 8 insertions, 40 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/reloader.rb b/actionpack/lib/action_dispatch/middleware/reloader.rb
index b84410fc62..579b5d8a02 100644
--- a/actionpack/lib/action_dispatch/middleware/reloader.rb
+++ b/actionpack/lib/action_dispatch/middleware/reloader.rb
@@ -25,26 +25,14 @@ module ActionDispatch
# Add a preparation callback. Preparation callbacks are run before each
# request.
- #
- # If a symbol with a block is given, the symbol is used as an identifier.
- # That allows to_prepare to be called again with the same identifier to
- # replace the existing callback. Passing an identifier is a suggested
- # practice if the code adding a preparation block may be reloaded.
def self.to_prepare(*args, &block)
- first_arg = args.first
- if first_arg.is_a?(Symbol) && block_given?
- remove_method :"__#{first_arg}" if method_defined?(:"__#{first_arg}")
- define_method :"__#{first_arg}", &block
- set_callback(:prepare, :"__#{first_arg}")
- else
- set_callback(:prepare, *args, &block)
- end
+ set_callback(:prepare, *args, &block)
end
# Add a cleanup callback. Cleanup callbacks are run after each request is
# complete (after #close is called on the response body).
- def self.to_cleanup(&block)
- set_callback(:cleanup, &block)
+ def self.to_cleanup(*args, &block)
+ set_callback(:cleanup, *args, &block)
end
def self.prepare!
@@ -55,11 +43,6 @@ module ActionDispatch
new(nil).send(:_run_cleanup_callbacks)
end
- def self.reload!
- prepare!
- cleanup!
- end
-
def initialize(app)
@app = app
end
diff --git a/actionpack/test/dispatch/reloader_test.rb b/actionpack/test/dispatch/reloader_test.rb
index 58ef346b5c..995b19030c 100644
--- a/actionpack/test/dispatch/reloader_test.rb
+++ b/actionpack/test/dispatch/reloader_test.rb
@@ -20,16 +20,6 @@ class ReloaderTest < Test::Unit::TestCase
assert_equal 3, c
end
- def test_to_prepare_with_identifier_replaces
- a = b = 0
- Reloader.to_prepare(:unique_id) { |*args| a = b = 1 }
- Reloader.to_prepare(:unique_id) { |*args| a = 2 }
-
- call_and_return_body
- assert_equal 2, a
- assert_equal 0, b
- end
-
class MyBody < Array
def initialize(&block)
@on_close = block
@@ -50,7 +40,7 @@ class ReloaderTest < Test::Unit::TestCase
def test_returned_body_object_always_responds_to_close
body = call_and_return_body
- assert body.respond_to?(:close)
+ assert_respond_to body, :close
end
def test_returned_body_object_behaves_like_underlying_object
@@ -83,10 +73,10 @@ class ReloaderTest < Test::Unit::TestCase
body = call_and_return_body do
[200, { "Content-Type" => "text/html" }, MyBody.new]
end
- assert body.respond_to?(:size)
- assert body.respond_to?(:each)
- assert body.respond_to?(:foo)
- assert body.respond_to?(:bar)
+ assert_respond_to body, :size
+ assert_respond_to body, :each
+ assert_respond_to body, :foo
+ assert_respond_to body, :bar
end
def test_cleanup_callbacks_are_called_when_body_is_closed
@@ -124,11 +114,6 @@ class ReloaderTest < Test::Unit::TestCase
Reloader.cleanup!
assert !prepared
assert cleaned
-
- prepared = cleaned = false
- Reloader.reload!
- assert prepared
- assert cleaned
end
private