diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-24 13:45:07 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-24 13:49:52 -0700 |
commit | 2237ee059669aa8b65355fa9c8d4b426d4ae113c (patch) | |
tree | 616a63bf22f2a30fe3910ab3b41b0da3df0b02ac /actionpack/test | |
parent | bd94e6de37307adad13fbdd6b4f7c5ed252adfa3 (diff) | |
download | rails-2237ee059669aa8b65355fa9c8d4b426d4ae113c.tar.gz rails-2237ee059669aa8b65355fa9c8d4b426d4ae113c.tar.bz2 rails-2237ee059669aa8b65355fa9c8d4b426d4ae113c.zip |
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.
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/abstract_unit.rb | 41 |
1 files changed, 29 insertions, 12 deletions
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) |