Skip to content

Commit

Permalink
Merge pull request #18392 from brainopia/fix_route_requirements
Browse files Browse the repository at this point in the history
Correct route requirements by overriding defaultls
  • Loading branch information
Arthur Nogueira Neves authored and arthurnn committed Apr 27, 2015
1 parent c9e354b commit fb14311
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_dispatch/journey/route.rb
Expand Up @@ -36,7 +36,7 @@ def ast

def requirements # :nodoc:
# needed for rails `rake routes`
path.requirements.merge(@defaults).delete_if { |_,v|
@defaults.merge(path.requirements).delete_if { |_,v|
/.+?/ == v
}
end
Expand Down
8 changes: 8 additions & 0 deletions actionpack/test/journey/route_test.rb
Expand Up @@ -25,6 +25,14 @@ def test_route_adds_itself_as_memo
end
end

def test_path_requirements_override_defaults
strexp = Router::Strexp.build(':name', { name: /love/ }, ['/'])
path = Path::Pattern.new strexp
defaults = { name: 'tender' }
route = Route.new('name', nil, path, nil, defaults)
assert_equal /love/, route.requirements[:name]
end

def test_ip_address
path = Path::Pattern.from_string '/messages/:id(.:format)'
route = Route.new("name", nil, path, {:ip => '192.168.1.1'},
Expand Down

0 comments on commit fb14311

Please sign in to comment.