diff options
author | Nicholas Seckar <nseckar@gmail.com> | 2006-08-06 02:51:53 +0000 |
---|---|---|
committer | Nicholas Seckar <nseckar@gmail.com> | 2006-08-06 02:51:53 +0000 |
commit | cbc3afb8786a9e6caa486fa2c97b17348c9eff51 (patch) | |
tree | 949c86a1371ea2d3aff00af4398581c4cf6f00cd /railties/test/dispatcher_test.rb | |
parent | 000a8ed9c688afe167f1d4cd4b6327d350272444 (diff) | |
download | rails-cbc3afb8786a9e6caa486fa2c97b17348c9eff51.tar.gz rails-cbc3afb8786a9e6caa486fa2c97b17348c9eff51.tar.bz2 rails-cbc3afb8786a9e6caa486fa2c97b17348c9eff51.zip |
Add Dispatcher.to_prepare and config.to_prepare to provide a pre-request hook.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4686 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/test/dispatcher_test.rb')
-rw-r--r-- | railties/test/dispatcher_test.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/railties/test/dispatcher_test.rb b/railties/test/dispatcher_test.rb index 41d08e224e..8fb19b173a 100644 --- a/railties/test/dispatcher_test.rb +++ b/railties/test/dispatcher_test.rb @@ -24,6 +24,8 @@ class DispatcherTest < Test::Unit::TestCase def setup @output = StringIO.new ENV['REQUEST_METHOD'] = "GET" + Dispatcher.send(:preparation_callbacks).clear + Dispatcher.send(:preparation_callbacks_run=, false) end def teardown @@ -84,6 +86,53 @@ class DispatcherTest < Test::Unit::TestCase ensure $stdin = old_stdin end + + def test_preparation_callbacks + Object.const_set :ApplicationController, nil + old_mechanism = Dependencies.mechanism + + a = b = c = nil + Dispatcher.to_prepare { a = b = c = 1 } + Dispatcher.to_prepare { b = c = 2 } + Dispatcher.to_prepare { c = 3 } + + Dispatcher.send :prepare_application + + assert_equal 1, a + assert_equal 2, b + assert_equal 3, c + + # When mechanism is :load, perform the callbacks each request: + Dependencies.mechanism = :load + a = b = c = nil + Dispatcher.send :prepare_application + assert_equal 1, a + assert_equal 2, b + assert_equal 3, c + + # But when not :load, make sure they are only run once + a = b = c = nil + Dependencies.mechanism = :not_load + Dispatcher.send :prepare_application + assert_equal nil, a || b || c + ensure + Dependencies.mechanism = old_mechanism + Object.send :remove_const, :ApplicationController + end + + def test_to_prepare_with_identifier_replaces + Object.const_set :ApplicationController, nil + + a = b = nil + Dispatcher.to_prepare(:unique_id) { a = b = 1 } + Dispatcher.to_prepare(:unique_id) { a = 2 } + + Dispatcher.send :prepare_application + assert_equal 2, a + assert_equal nil, b + ensure + Object.send :remove_const, :ApplicationController + end private def dispatch |