mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
dispatcher test cosmetics
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4847 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -24,30 +24,34 @@ 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
|
||||
Object.send :remove_const, :ApplicationController
|
||||
ENV['REQUEST_METHOD'] = nil
|
||||
end
|
||||
|
||||
def test_ac_subclasses_cleared_on_reset
|
||||
Object.class_eval(ACTION_CONTROLLER_DEF)
|
||||
assert_equal 1, ActionController::Base.subclasses.length
|
||||
assert_subclasses 1, ActionController::Base
|
||||
dispatch
|
||||
|
||||
GC.start # force the subclass to be collected
|
||||
assert_equal 0, ActionController::Base.subclasses.length
|
||||
assert_subclasses 0, ActionController::Base
|
||||
end
|
||||
|
||||
def test_am_subclasses_cleared_on_reset
|
||||
Object.class_eval(ACTION_MAILER_DEF)
|
||||
assert_equal 1, ActionMailer::Base.subclasses.length
|
||||
assert_subclasses 1, ActionMailer::Base
|
||||
dispatch
|
||||
|
||||
GC.start # force the subclass to be collected
|
||||
assert_equal 0, ActionMailer::Base.subclasses.length
|
||||
assert_subclasses 0, ActionMailer::Base
|
||||
end
|
||||
|
||||
|
||||
@@ -78,9 +82,7 @@ class DispatcherTest < Test::Unit::TestCase
|
||||
[EMPTY_CONTENT, CONTENT_LENGTH_MISMATCH, NONINTEGER_CONTENT_LENGTH].each do |bad_request|
|
||||
$stdin = StringIO.new(bad_request)
|
||||
output = StringIO.new
|
||||
assert_nothing_raised do
|
||||
Dispatcher.dispatch(nil, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, output)
|
||||
end
|
||||
assert_nothing_raised { dispatch output }
|
||||
assert_equal "Status: 400 Bad Request\r\n", output.string
|
||||
end
|
||||
ensure
|
||||
@@ -88,7 +90,6 @@ class DispatcherTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_preparation_callbacks
|
||||
Object.const_set :ApplicationController, nil
|
||||
old_mechanism = Dependencies.mechanism
|
||||
|
||||
a = b = c = nil
|
||||
@@ -117,12 +118,9 @@ class DispatcherTest < Test::Unit::TestCase
|
||||
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 }
|
||||
@@ -130,12 +128,14 @@ class DispatcherTest < Test::Unit::TestCase
|
||||
Dispatcher.send :prepare_application
|
||||
assert_equal 2, a
|
||||
assert_equal nil, b
|
||||
ensure
|
||||
Object.send :remove_const, :ApplicationController
|
||||
end
|
||||
|
||||
private
|
||||
def dispatch
|
||||
Dispatcher.dispatch(nil, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, @output)
|
||||
def dispatch(output = @output)
|
||||
Dispatcher.dispatch(nil, {}, output)
|
||||
end
|
||||
|
||||
def assert_subclasses(howmany, klass, message = klass.subclasses.inspect)
|
||||
assert_equal howmany, klass.subclasses.size, message
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user