From 2237ee059669aa8b65355fa9c8d4b426d4ae113c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 24 Aug 2015 13:45:07 -0700 Subject: subclass and delegate rather than mutating existing objects If we subclass and augment the superclass, then we don't need to have setters for particular things on the superclass. --- actionpack/test/abstract_unit.rb | 41 ++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) (limited to 'actionpack/test') diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 0fe9602fe7..f014ec54bc 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -116,23 +116,40 @@ class ActionDispatch::IntegrationTest < ActiveSupport::TestCase 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 - protected - def controller_reference(controller_param) - controller_param.params[:controller] + class DeadEndRoutes < ActionDispatch::Routing::RouteSet + # Stub Rails dispatcher so it does not get controller references and + # simply return the controller#action as Rack::Body. + class NullController + def initialize(controller_name) + @controller = controller_name + @action = nil + end + + def action(action_name) + @action = action_name + self + end + + def call(env) + [200, {'Content-Type' => 'text/html'}, ["#{@controller}##{@action}"]] + end + + def new; self; end + end + + class NullControllerRequest < DelegateClass(ActionDispatch::Request) + def controller_class + NullController.new params[:controller] + end end - def dispatch(controller, action, env) - [200, {'Content-Type' => 'text/html'}, ["#{controller}##{action}"]] + def make_request env + NullControllerRequest.new super end end - def self.stub_controllers(config = nil) - route_set = ActionDispatch::Routing::RouteSet.new(*[config].compact) - route_set.dispatcher_class = StubDispatcher - yield route_set + def self.stub_controllers(config = ActionDispatch::Routing::RouteSet::DEFAULT_CONFIG) + yield DeadEndRoutes.new(config) end def with_routing(&block) -- cgit v1.2.3