Module Spec::Rails::Example::RoutingHelpers

  1. lib/spec/rails/example/routing_helpers.rb

Methods

public instance

  1. params_from
  2. route_for

Public instance methods

params_from (method, path)

Uses ActionController::Routing::Routes to parse an incoming path so the parameters it generates can be checked

Note that this method is obsoleted by the route_to matcher.

Example

params_from(:get, '/registrations/1/edit')
  => :controller => 'registrations', :action => 'edit', :id => '1'
[show source]
# File lib/spec/rails/example/routing_helpers.rb, line 50
        def params_from(method, path)
          ensure_that_routes_are_loaded
          path, querystring = path.split('?')
          params = ActionController::Routing::Routes.recognize_path(path, :method => method)
          querystring.blank? ? params : params.merge(Rack::Utils.parse_query(querystring).symbolize_keys!)
        end
route_for (options)

Uses ActionController::Routing::Routes to generate the correct route for a given set of options.

Examples

route_for(:controller => 'registrations', :action => 'edit', :id => '1')
  => '/registrations/1/edit'
route_for(:controller => 'registrations', :action => 'create')
  => {:path => "/registrations", :method => :post}
[show source]
# File lib/spec/rails/example/routing_helpers.rb, line 39
        def route_for(options)
          RouteFor.new(self, options)
        end