aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/lib/action_dispatch/middleware/reloader.rb23
-rw-r--r--actionpack/test/dispatch/reloader_test.rb25
-rw-r--r--activerecord/lib/active_record/railtie.rb2
-rw-r--r--railties/lib/rails/console/app.rb3
-rw-r--r--railties/test/application/console_test.rb6
5 files changed, 14 insertions, 45 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
diff --git a/activerecord/lib/active_record/railtie.rb b/activerecord/lib/active_record/railtie.rb
index 61fb0ae468..2accf0a48f 100644
--- a/activerecord/lib/active_record/railtie.rb
+++ b/activerecord/lib/active_record/railtie.rb
@@ -80,7 +80,7 @@ module ActiveRecord
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
diff --git a/railties/lib/rails/console/app.rb b/railties/lib/rails/console/app.rb
index 4a988efd82..95c74baae2 100644
--- a/railties/lib/rails/console/app.rb
+++ b/railties/lib/rails/console/app.rb
@@ -26,6 +26,7 @@ end
# reloads the environment
def reload!(print=true)
puts "Reloading..." if print
- ActionDispatch::Reloader.reload!
+ ActionDispatch::Reloader.cleanup!
+ ActionDispatch::Reloader.prepare!
true
end
diff --git a/railties/test/application/console_test.rb b/railties/test/application/console_test.rb
index 5f84c2b948..793e73556c 100644
--- a/railties/test/application/console_test.rb
+++ b/railties/test/application/console_test.rb
@@ -31,9 +31,9 @@ class ConsoleTest < Test::Unit::TestCase
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! }