Skip to content

Instantly share code, notes, and snippets.

@dariocravero
Created October 4, 2010 00:13
Show Gist options
  • Save dariocravero/609077 to your computer and use it in GitHub Desktop.
Save dariocravero/609077 to your computer and use it in GitHub Desktop.
In:
http://github.com/dariocravero/padrino-framework/blob/map-forward-slash/padrino-core/test/test_routing.rb#L502
should 'apply maps' do
mock_app do
controllers :admin do
get(:index, :map => "/"){ "index" }
get(:show, :with => :id, :map => "/show"){ "show #{params[:id]}" }
get(:edit, :map => "/edit/:id/product"){ "edit #{params[:id]}" }
get(:wacky, :map => "/wacky-:id-:product_id"){ "wacky #{params[:id]}-#{params[:product_id]}" }
end
end
get "/"
assert_equal "index", body
get @app.url(:admin, :index)
assert_equal "index", body
get "/show/1"
assert_equal "show 1", body
get "/edit/1/product"
assert_equal "edit 1", body
get "/wacky-1-2"
assert_equal "wacky 1-2", body
end
In
http://github.com/dariocravero/padrino-framework/blob/map-forward-slash/padrino-core/lib/padrino-core/application/routing.rb#L453
def parse_route(path, options, verb)
...
# Small reformats
path.gsub!(%r{/?index/?}, '') # Remove index path
path[0,0] = "/" unless path =~ %r{^\(?/} # Paths must start with a /
path.sub!(%r{/(\))?$}, '\\1') if path != "/" # Remove latest trailing delimiter
path.gsub!(/\/(\(\.|$)/, '\\1') if path != "/" # Remove trailing slashes
end
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment