Skip to content
This repository has been archived by the owner on Sep 13, 2017. It is now read-only.

Commit

Permalink
testing empty formats
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 30, 2011
1 parent b1c3b03 commit 4c1d105
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/journey/route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def visit_GROUP node
end
end

def visit_SEGMENT node
segment = super
segment == '/' ? '' : segment
end

def visit_SYMBOL node
key = node.to_sym

Expand Down
4 changes: 3 additions & 1 deletion lib/journey/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def call env

def recognize req
match_data, route = route_for req.env
yield(route, nil, match_data.merge(route.extras))
yield(route, nil, match_data)
end

private
Expand All @@ -59,6 +59,8 @@ def route_for env
match_data = route.path =~ env['PATH_INFO']
end

return unless route

[match_data.merge(route.extras), route]
end
end
Expand Down
8 changes: 8 additions & 0 deletions test/test_route.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def test_initialize
assert_equal defaults, route.extras
end

def test_format_empty
path = Path::Pattern.new '/messages/:id(.:format)'
route = Route.new(nil, path, nil,
{ :controller => 'foo', :action => 'bar' })

assert_equal ['/messages', {}], route.format({})
end

def test_connects_all_match
path = Path::Pattern.new '/:controller(/:action(/:id(.:format)))'
route = Route.new(nil, path, nil,
Expand Down

0 comments on commit 4c1d105

Please sign in to comment.