Module: Merb::Test::RouteHelper
- Includes:
- RequestHelper
- Included in:
- ExampleGroup, Spec::Matchers::MatcherDSL
- Defined in:
- lib/merb-core/test/helpers/route_helper.rb
Instance Method Summary collapse
-
#request_to(path, method = :get, env = {}) ⇒ Object
Parameters path<~to_string>:: The URL of the request.
-
#resource(*args) ⇒ Object
Mimics the resource method available to controllers.
-
#url(*args) ⇒ Object
There are three possible ways to use this method.
Methods included from RequestHelper
#build_request, #check_request_for_route, #delete, #describe_input, #describe_request, #dispatch_request, #dispatch_to, #dispatch_with_basic_authentication_to, #fake_request, #get, #merge_controller_and_action, #mock_request, #post, #put, #requesting, #response_for, #status_code, #with_cookies
Methods included from MakeRequest
Instance Method Details
#request_to(path, method = :get, env = {}) ⇒ Object
Parameters
- path<~to_string>
-
The URL of the request.
- method<~to_sym>
-
HTTP request method.
- env<Hash>
-
Additional parameters for the request.
Returns
- Hash
-
A hash containing the controller and action along with any parameters
85 86 87 88 89 90 |
# File 'lib/merb-core/test/helpers/route_helper.rb', line 85 def request_to(path, method = :get, env = {}) env[:request_method] ||= method.to_s.upcase env[:request_uri] = path check_request_for_route(build_request({}, env)) end |
#resource(*args) ⇒ Object
Mimics the resource method available to controllers
Paramaters
- resources<Object>
-
The resources to generate URLs from
- params<Hash>
-
Any extra parameters that are required.
Returns
- String
-
The generated URL.
73 74 75 76 |
# File 'lib/merb-core/test/helpers/route_helper.rb', line 73 def resource(*args) args << @request_params || {} Merb::Router.resource(*args) end |
#url(*args) ⇒ Object
There are three possible ways to use this method. First, if you have a named route, you can specify the route as the first parameter as a symbol and any paramters in a hash. Second, you can generate the default route by just passing the params hash, just passing the params hash. Finally, you can use the anonymous parameters. This allows you to specify the parameters to a named route in the order they appear in the router.
Parameters(Named Route)
- name<Symbol>
-
The name of the route.
- args<Hash>
-
Parameters for the route generation.
Parameters(Default Route)
- args<Hash>
-
Parameters for the route generation. This route will use the default route.
Parameters(Anonymous Parameters)
- name<Symbol>
-
The name of the route.
- args<Array>
-
An array of anonymous parameters to generate the route with. These parameters are assigned to the route parameters in the order that they are passed.
Returns
- String
-
The generated URL.
Examples
Named Route
Merb::Router.prepare do
match("/articles/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, :title => “new_article”)
Default Route
Merb::Router.prepare do
default_routes
end
url(:controller => “articles”, :action => “new”)
Anonymous Paramters
Merb::Router.prepare do
match("/articles/:year/:month/:title").to(:controller => :articles, :action => :show).name("articles")
end
url(:articles, 2008, 10, “test_article”)
:api: public
60 61 62 63 |
# File 'lib/merb-core/test/helpers/route_helper.rb', line 60 def url(*args) args << (@request_params || {}) Merb::Router.url(*args) end |