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

Commit

Permalink
* lib/journey/formatter.rb: when generating routes, skip route
Browse files Browse the repository at this point in the history
  literals (routes that do not have replacement values like
  "/:controller") when matching unnamed routes.

    rails/rails#6459

* test/test_router.rb: corresponding test

Conflicts:

	lib/journey/formatter.rb
  • Loading branch information
tenderlove committed Jun 14, 2012
1 parent 361af48 commit c70e548
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/journey/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def generate key, name, options, recall = {}, parameterize = nil

parameterized_parts.keep_if { |_,v| v }

next if !name && route.requirements.empty? && route.parts.empty?

This comment has been minimized.

Copy link
@pixeltrix

pixeltrix Aug 9, 2012

Shouldn't that be route.path.requirements.empty? otherwise it'll never be empty since it will include the defaults like :controller and :action merged in.

This comment has been minimized.

Copy link
@pixeltrix

pixeltrix Aug 9, 2012

Actually it will be empty, but only for mounted applications - is that what the line is for? Is it there just to skip unnamed routes matching against engines?

This comment has been minimized.

Copy link
@tenderlove

tenderlove Aug 9, 2012

Author Member

Yes, I believe that is correct. This test demonstrates the use.


next unless verify_required_parts!(route, parameterized_parts)

z = Hash[options.to_a - data.to_a - route.defaults.to_a]
Expand Down
7 changes: 4 additions & 3 deletions test/test_router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,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
Expand Down

0 comments on commit c70e548

Please sign in to comment.