Browse files

Allow setting a default application for all integration tests

  • Loading branch information...
1 parent b0506b0 commit 14866fa3d83676d340d94464f50e2e0ea989c3c1 @josh josh committed Sep 26, 2009
View
22 actionpack/lib/action_dispatch/testing/integration.rb
@@ -325,6 +325,10 @@ def capture_instantiation
end
module Runner
+ def app
+ @app
+ end
+
# Reset the current session. This is useful for testing multiple sessions
# in a single test case.
def reset!
@@ -354,8 +358,7 @@ def reset!
# can use this method to open multiple sessions that ought to be tested
# simultaneously.
def open_session(app = nil)
- app ||= @app ||= ActionController::Dispatcher.new
- session = Integration::Session.new(app)
+ session = Integration::Session.new(app || self.app)
# delegate the fixture accessors back to the test instance
extras = Module.new { attr_accessor :delegate, :test_result }
@@ -477,5 +480,20 @@ def method_missing(sym, *args, &block)
# end
class IntegrationTest < ActiveSupport::TestCase
include Integration::Runner
+
+ @@app = nil
+
+ def self.app
+ # DEPRECATE AC::Dispatcher fallback
+ @@app || ActionController::Dispatcher.new
+ end
+
+ def self.app=(app)
+ @@app = app
+ end
+
+ def app
+ super || self.class.app
+ end
end
end
View
12 actionpack/test/abstract_unit.rb
@@ -52,11 +52,13 @@
FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
-ActionController::Dispatcher.middleware = ActionDispatch::MiddlewareStack.new do |middleware|
- middleware.use "ActionDispatch::ShowExceptions"
- middleware.use "ActionDispatch::Callbacks"
- middleware.use "ActionDispatch::ParamsParser"
- middleware.use "Rack::Head"
+class ActionController::IntegrationTest < ActiveSupport::TestCase
+ @@app = ActionDispatch::MiddlewareStack.new { |middleware|
+ middleware.use "ActionDispatch::ShowExceptions"
+ middleware.use "ActionDispatch::Callbacks"
+ middleware.use "ActionDispatch::ParamsParser"
+ middleware.use "Rack::Head"
+ }.build(ActionController::Routing::Routes)
end
module ActionView
View
3 actionpack/test/controller/dispatcher_test.rb
@@ -22,7 +22,6 @@ def setup
def teardown
Dispatcher.router = @old_router
- @dispatcher = nil
ENV.delete 'REQUEST_METHOD'
end
@@ -79,7 +78,7 @@ def dispatch(cache_classes = true)
ActionController::Dispatcher.prepare_each_request = false
Dispatcher.define_dispatcher_callbacks(cache_classes)
- @dispatcher ||= Dispatcher.new
+ @dispatcher ||= ActionDispatch::Callbacks.new(Dispatcher.router)
@dispatcher.call({'rack.input' => StringIO.new(''), 'action_dispatch.show_exceptions' => false})
end

0 comments on commit 14866fa

Please sign in to comment.