Skip to content

Commit

Permalink
Refactor to remove DrawOnce module
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
eileencodes committed Aug 8, 2015
1 parent e7007e3 commit c8b8295
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions actionpack/test/abstract_unit.rb
Expand Up @@ -63,42 +63,21 @@ def env

SharedTestRoutes = ActionDispatch::Routing::RouteSet.new

SharedTestRoutes.draw do
get ':controller(/:action)'
end

module ActionDispatch
module SharedRoutes
def before_setup
@routes = SharedTestRoutes
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
Expand All @@ -119,8 +98,6 @@ def call(env)
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")
Expand All @@ -136,6 +113,10 @@ def self.build_app(routes = nil)

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
Expand Down

0 comments on commit c8b8295

Please sign in to comment.