1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Refactor to remove DrawOnce module

We were doing extra work that could be pushed off to Integration test
and SharedRoutes. Creating an extra module isn't necessary when those
are created by their respective classes.
This commit is contained in:
eileencodes 2015-08-08 10:15:35 -04:00
parent e7007e384c
commit c8b8295583

View file

@ -63,6 +63,10 @@ FIXTURE_LOAD_PATH = File.join(File.dirname(__FILE__), 'fixtures')
SharedTestRoutes = ActionDispatch::Routing::RouteSet.new
SharedTestRoutes.draw do
get ':controller(/:action)'
end
module ActionDispatch
module SharedRoutes
def before_setup
@ -70,35 +74,10 @@ module ActionDispatch
super
end
end
# Hold off drawing routes until all the possible controller classes
# have been loaded.
module DrawOnce
class << self
attr_accessor :drew
end
self.drew = false
def before_setup
super
return if DrawOnce.drew
SharedTestRoutes.draw do
get ':controller(/:action)'
end
ActionDispatch::IntegrationTest.app.routes.draw do
get ':controller(/:action)'
end
DrawOnce.drew = true
end
end
end
module ActiveSupport
class TestCase
include ActionDispatch::DrawOnce
if RUBY_ENGINE == "ruby" && PROCESS_COUNT > 0
parallelize_me!
end
@ -119,8 +98,6 @@ class RoutedRackApp
end
class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
include ActionDispatch::SharedRoutes
def self.build_app(routes = nil)
RoutedRackApp.new(routes || ActionDispatch::Routing::RouteSet.new) do |middleware|
middleware.use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
@ -136,6 +113,10 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase
self.app = build_app
app.routes.draw do
get ':controller(/:action)'
end
# Stub Rails dispatcher so it does not get controller references and
# simply return the controller#action as Rack::Body.
class StubDispatcher < ::ActionDispatch::Routing::RouteSet::Dispatcher