aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/abstract_unit.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-07-02 15:02:36 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-07-15 15:19:41 -0700
commit8eb7bcb6e59e5720e3bd322511817804c8087043 (patch)
treeef088233869d43cbd05e8dec6603e602db8f2da9 /actionpack/test/abstract_unit.rb
parenta3ca700c58fa59722288a12960c4a6cd1ade6aea (diff)
downloadrails-8eb7bcb6e59e5720e3bd322511817804c8087043.tar.gz
rails-8eb7bcb6e59e5720e3bd322511817804c8087043.tar.bz2
rails-8eb7bcb6e59e5720e3bd322511817804c8087043.zip
stop calling url_for with recall parameters and actually use a request
Diffstat (limited to 'actionpack/test/abstract_unit.rb')
-rw-r--r--actionpack/test/abstract_unit.rb77
1 files changed, 74 insertions, 3 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index 6584d20840..d027f1a88d 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -305,15 +305,44 @@ end
module ActionDispatch
module RoutingVerbs
- def get(uri_or_host, path = nil)
+ def send_request(uri_or_host, method, path)
host = uri_or_host.host unless path
path ||= uri_or_host.path
params = {'PATH_INFO' => path,
- 'REQUEST_METHOD' => 'GET',
+ 'REQUEST_METHOD' => method,
'HTTP_HOST' => host}
- routes.call(params)[2].join
+ routes.call(params)
+ end
+
+ def request_path_params(path, method: 'GET')
+ resp = send_request URI('http://localhost' + path), method.to_s.upcase, nil
+ status, headers, body = *resp
+ if status == 404
+ raise ActionController::RoutingError, "No route matches #{path.inspect}"
+ end
+ controller.request.path_parameters
+ end
+
+ def get(uri_or_host, path = nil)
+ send_request(uri_or_host, 'GET', path)[2].join
+ end
+
+ def post(uri_or_host, path = nil)
+ send_request(uri_or_host, 'POST', path)[2].join
+ end
+
+ def put(uri_or_host, path = nil)
+ send_request(uri_or_host, 'PUT', path)[2].join
+ end
+
+ def delete(uri_or_host, path = nil)
+ send_request(uri_or_host, 'DELETE', path)[2].join
+ end
+
+ def patch(uri_or_host, path = nil)
+ send_request(uri_or_host, 'PATCH', path)[2].join
end
end
end
@@ -322,6 +351,48 @@ module RoutingTestHelpers
def url_for(set, options, recall = {})
set.url_for options.merge(:only_path => true, :_recall => recall)
end
+
+ def make_set(strict = true)
+ tc = self
+ TestSet.new ->(c) { tc.controller = c }, strict
+ end
+
+ class TestSet < ActionDispatch::Routing::RouteSet
+ attr_reader :strict
+
+ def initialize(block, strict = false)
+ @block = block
+ @strict = strict
+ super()
+ end
+
+ class Dispatcher < ActionDispatch::Routing::RouteSet::Dispatcher
+ def initialize(defaults, set, block)
+ super(defaults)
+ @block = block
+ @set = set
+ end
+
+ def controller(params, default_controller=true)
+ super(params, @set.strict)
+ end
+
+ def controller_reference(controller_param)
+ block = @block
+ set = @set
+ super if @set.strict
+ Class.new(ActionController::Base) {
+ include set.url_helpers
+ define_method(:process) { |name| block.call(self) }
+ def to_a; [200, {}, []]; end
+ }
+ end
+ end
+
+ def dispatcher defaults
+ TestSet::Dispatcher.new defaults, self, @block
+ end
+ end
end
class ResourcesController < ActionController::Base