Sha256: a01a45196e4aab9ab652dc670960a04879a5ebe316a81d5e9faa09f9076f2120
Contents?: true
Size: 1.86 KB
Versions: 4
Compression:
Stored size: 1.86 KB
Contents
module Spec module Rails module Example module RoutingHelpers class RouteFor def initialize(example, options) @example, @options = example, options end def ==(expected) if Hash === expected path, querystring = expected[:path].split('?') path = expected.merge(:path => path) else path, querystring = expected.split('?') end params = querystring.blank? ? {} : @example.params_from_querystring(querystring) @example.assert_recognizes(@options, path, params) true end end # Uses ActionController::Routing::Routes to generate # the correct route for a given set of options. # == Example # route_for(:controller => 'registrations', :action => 'edit', :id => 1) # => '/registrations/1;edit' def route_for(options) RouteFor.new(self, options) end # Uses ActionController::Routing::Routes to parse # an incoming path so the parameters it generates can be checked # == Example # params_from(:get, '/registrations/1/edit') # => :controller => 'registrations', :action => 'edit', :id => 1 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(params_from_querystring(querystring)) end def params_from_querystring(querystring) # :nodoc: params = {} querystring.split('&').each do |piece| key, value = piece.split('=') params[key.to_sym] = value end params end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems