Browse files

* lib/journey/formatter.rb: when generating routes, skip route

  literals (routes that do not have replacement values like
  "/:controller") when matching unnamed routes.

    rails/rails#6459

* test/test_router.rb: corresponding test
  • Loading branch information...
1 parent 8f7d3b0 commit 45d4e9eb7bd5143251b1c884e6a0f23828c0ece7 @tenderlove tenderlove committed Jun 14, 2012
Showing with 16 additions and 4 deletions.
  1. +10 −0 CHANGELOG.rdoc
  2. +2 −1 lib/journey/formatter.rb
  3. +4 −3 test/test_router.rb
View
10 CHANGELOG.rdoc
@@ -1,3 +1,13 @@
+Thu Jun 14 14:03:22 2012 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * lib/journey/formatter.rb: when generating routes, skip route
+ literals (routes that do not have replacement values like
+ "/:controller") when matching unnamed routes.
+
+ https://github.com/rails/rails/issues/6459
+
+ * test/test_router.rb: corresponding test
+
Wed Feb 15 11:49:41 2012 Aaron Patterson <aaron@tenderlovemaking.com>
* lib/journey/formatter.rb: reject non-truthy parameters parts.
View
3 lib/journey/formatter.rb
@@ -14,7 +14,6 @@ def generate type, name, options, recall = {}, parameterize = nil
constraints = recall.merge options
match_route(name, constraints) do |route|
-
keys_to_keep = route.parts.reverse.drop_while { |part|
!options.key?(part) || (options[part] || recall[part]).nil?
}
@@ -31,6 +30,8 @@ def generate type, name, options, recall = {}, parameterize = nil
parameterized_parts.keep_if { |_,v| v }
+ next if !name && route.requirements.empty? && route.parts.empty?
+
next unless verify_required_parts!(route, parameterized_parts)
params = options.dup.delete_if do |key, _|
View
7 test/test_router.rb
@@ -302,11 +302,12 @@ def test_nil_path_parts_are_ignored
end
def test_generate_slash
- path = Path::Pattern.new '/'
- @router.routes.add_route nil, path, {}, {}, {}
-
params = [ [:controller, "tasks"],
[:action, "show"] ]
+ str = Router::Strexp.new("/", Hash[params], ['/', '.', '?'], true)
+ path = Path::Pattern.new str
+
+ @router.routes.add_route nil, path, {}, {}, {}
path, _ = @formatter.generate(:path_info, nil, Hash[params], {})
assert_equal '/', path

0 comments on commit 45d4e9e

Please sign in to comment.