Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Small changes on AD::Reloader.

  • Loading branch information...
commit 0cbfd6c28d327304432f7d0c067662b5c1e41a78 1 parent e683ab7
@josevalim josevalim authored
View
23 actionpack/lib/action_dispatch/middleware/reloader.rb
@@ -25,26 +25,14 @@ class Reloader
# 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 @@ def self.cleanup!
new(nil).send(:_run_cleanup_callbacks)
end
- def self.reload!
- prepare!
- cleanup!
- end
-
def initialize(app)
@app = app
end
View
25 actionpack/test/dispatch/reloader_test.rb
@@ -20,16 +20,6 @@ def test_prepare_callbacks
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 @@ def close
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 @@ def test_returned_body_object_responds_to_all_methods_supported_by_underlying_ob
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 @@ def test_manual_reloading
Reloader.cleanup!
assert !prepared
assert cleaned
-
- prepared = cleaned = false
- Reloader.reload!
- assert prepared
- assert cleaned
end
private
View
2  activerecord/lib/active_record/railtie.rb
@@ -80,7 +80,7 @@ class Railtie < Rails::Railtie
ActiveSupport.on_load(:active_record) do
instantiate_observers
- ActionDispatch::Reloader.to_prepare(:activerecord_instantiate_observers) do
+ ActionDispatch::Reloader.to_prepare do
ActiveRecord::Base.instantiate_observers
end
end
View
3  railties/lib/rails/console/app.rb
@@ -26,6 +26,7 @@ def new_session
# reloads the environment
def reload!(print=true)
puts "Reloading..." if print
- ActionDispatch::Reloader.reload!
+ ActionDispatch::Reloader.cleanup!
+ ActionDispatch::Reloader.prepare!
true
end
View
6 railties/test/application/console_test.rb
@@ -31,9 +31,9 @@ def test_reload_should_fire_preparation_and_cleanup_callbacks
a = b = c = nil
# TODO: These should be defined on the initializer
- ActionDispatch::Reloader.to_prepare { a = b = c = 1 }
- ActionDispatch::Reloader.to_prepare { b = c = 2 }
- ActionDispatch::Reloader.to_cleanup { c = 3 }
+ ActionDispatch::Reloader.to_cleanup { a = b = c = 1 }
+ ActionDispatch::Reloader.to_cleanup { b = c = 2 }
+ ActionDispatch::Reloader.to_prepare { c = 3 }
# Hide Reloading... output
silence_stream(STDOUT) { reload! }
Please sign in to comment.
Something went wrong with that request. Please try again.