aboutsummaryrefslogtreecommitdiffstats
path: root/railties/test
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-09-26 01:24:07 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-09-26 01:24:07 +0000
commitf08da31a4fc9624ed2621d156194c7e61261a141 (patch)
treed7dda866a152c9b3a785fb4b9f05eb4a8781abae /railties/test
parent6b2226aae91c994169d3ca5b5b047dfe7d1be747 (diff)
downloadrails-f08da31a4fc9624ed2621d156194c7e61261a141.tar.gz
rails-f08da31a4fc9624ed2621d156194c7e61261a141.tar.bz2
rails-f08da31a4fc9624ed2621d156194c7e61261a141.zip
Move Railties' Dispatcher to ActionController::Dispatcher, introduce before_ and after_dispatch callbacks, and warm up to non-CGI requests.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7640 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/test')
-rw-r--r--railties/test/console_app_test.rb4
-rw-r--r--railties/test/dispatcher_test.rb121
2 files changed, 4 insertions, 121 deletions
diff --git a/railties/test/console_app_test.rb b/railties/test/console_app_test.rb
index 0e6019df44..ac499e0f15 100644
--- a/railties/test/console_app_test.rb
+++ b/railties/test/console_app_test.rb
@@ -2,6 +2,10 @@ require File.dirname(__FILE__) + '/abstract_unit'
require 'action_controller' # console_app uses 'action_controller/integration'
+unless defined? ApplicationController
+ class ApplicationController < ActionController::Base; end
+end
+
require 'dispatcher'
require 'console_app'
diff --git a/railties/test/dispatcher_test.rb b/railties/test/dispatcher_test.rb
deleted file mode 100644
index 081d21f8d8..0000000000
--- a/railties/test/dispatcher_test.rb
+++ /dev/null
@@ -1,121 +0,0 @@
-require "#{File.dirname(__FILE__)}/abstract_unit"
-
-uses_mocha 'dispatcher tests' do
-
-$:.unshift File.dirname(__FILE__) + "/../../actionmailer/lib"
-
-require 'stringio'
-require 'cgi'
-
-require 'dispatcher'
-require 'action_controller'
-require 'action_mailer'
-
-
-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)
-
- Object.const_set 'ApplicationController', nil
- end
-
- def teardown
- ENV['REQUEST_METHOD'] = nil
- Object.send :remove_const, 'ApplicationController'
- end
-
- def test_clears_dependencies_after_dispatch_if_in_loading_mode
- Dependencies.stubs(:load?).returns(true)
-
- ActionController::Routing::Routes.expects(:reload).once
- Dependencies.expects(:clear).once
-
- dispatch
- end
-
- def test_clears_dependencies_after_dispatch_if_not_in_loading_mode
- Dependencies.stubs(:load?).returns(false)
-
- ActionController::Routing::Routes.expects(:reload).never
- Dependencies.expects(:clear).never
-
- dispatch
- end
-
- def test_failsafe_response
- CGI.expects(:new).raises('some multipart parsing failure')
-
- ActionController::Routing::Routes.stubs(:reload)
- Dispatcher.stubs(:log_failsafe_exception)
-
- assert_nothing_raised { dispatch }
-
- assert_equal "Status: 400 Bad Request\r\nContent-Type: text/html\r\n\r\n<html><body><h1>400 Bad Request</h1></body></html>", @output.string
- end
-
- def test_preparation_callbacks
- ActionController::Routing::Routes.stubs(:reload)
-
- 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
- end
-
- def test_to_prepare_with_identifier_replaces
- ActionController::Routing::Routes.stubs(:reload)
-
- 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
- end
-
- private
- def dispatch(output = @output)
- controller = mock
- controller.stubs(:process).returns(controller)
- controller.stubs(:out).with(output).returns('response')
-
- ActionController::Routing::Routes.stubs(:recognize).returns(controller)
-
- Dispatcher.dispatch(nil, {}, output)
- end
-
- def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
- assert_equal howmany, klass.subclasses.size, message
- end
-end
-
-end # uses_mocha