aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-02-15 00:51:02 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-02-15 00:51:02 +0000
commitc844755e5a0c3d4edfcc78f9c30ef91fa0de550a (patch)
tree4cf4890fc5af5f58dd0a6a19c0a6fea6ed39a1df /actionpack/lib/action_controller/assertions/action_pack_assertions.rb
parenta3298e5efdf33398b49933323ea3fef7ff4e9a9c (diff)
downloadrails-c844755e5a0c3d4edfcc78f9c30ef91fa0de550a.tar.gz
rails-c844755e5a0c3d4edfcc78f9c30ef91fa0de550a.tar.bz2
rails-c844755e5a0c3d4edfcc78f9c30ef91fa0de550a.zip
Merged back the Routing branch
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@614 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/assertions/action_pack_assertions.rb')
-rw-r--r--actionpack/lib/action_controller/assertions/action_pack_assertions.rb32
1 files changed, 31 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/assertions/action_pack_assertions.rb b/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
index c26941cd6b..7d27240244 100644
--- a/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
+++ b/actionpack/lib/action_controller/assertions/action_pack_assertions.rb
@@ -141,7 +141,7 @@ module Test #:nodoc:
end
end
end
-
+
# ensure our redirection url is an exact match
def assert_redirect_url(url=nil, message=nil)
assert_redirect(message)
@@ -158,6 +158,36 @@ module Test #:nodoc:
assert_block(msg) { response.redirect_url_match?(pattern) }
end
+ # -- routing assertions --------------------------------------------------
+
+ # Asserts that the routing of the given path is handled correctly and that the parsed options match.
+ # Also verifies that the provided options can be used to generate the provided path.
+ def assert_routing(path, options, defaults={}, extras={}, message=nil)
+ defaults[:controller] ||= options[:controller] # Assume given controller,
+ request = ActionController::TestRequest.new({}, {}, nil)
+ request.path_parameters = defaults
+
+ ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? # Load routes.rb if it hasn't been loaded.
+
+ generated_path, found_extras = ActionController::Routing::Routes.generate(defaults.merge(options), request)
+ generated_path = generated_path.join('/')
+ msg = build_message(message, "found extras <?>, not <?>", found_extras, extras)
+ assert_block(msg) { found_extras == extras }
+
+ msg = build_message(message, "The generated path <?> did not match <?>", generated_path, path)
+ assert_block(msg) { path == generated_path }
+
+ request = ActionController::TestRequest.new({}, {}, nil)
+ request.path = path
+ ActionController::Routing::Routes.recognize!(request)
+
+ expected_options = options.clone
+ extras.each {|k,v| expected_options.delete k}
+
+ msg = build_message(message, "The recognized options <?> did not match <?>", request.path_parameters, expected_options)
+ assert_block(msg) { request.path_parameters == expected_options }
+ end
+
# -- template assertions ------------------------------------------------
# ensure that a template object with the given name exists