Skip to content

Commit

Permalink
Revert "* lib/journey/formatter.rb: when generating routes, skip route"
Browse files Browse the repository at this point in the history
This reverts commit 45d4e9e.
  • Loading branch information
lifo committed Aug 14, 2012
1 parent e4755e0 commit 06208ad
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 16 deletions.
10 changes: 0 additions & 10 deletions CHANGELOG.rdoc
@@ -1,13 +1,3 @@
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> Wed Feb 15 11:49:41 2012 Aaron Patterson <aaron@tenderlovemaking.com>


* lib/journey/formatter.rb: reject non-truthy parameters parts. * lib/journey/formatter.rb: reject non-truthy parameters parts.
Expand Down
3 changes: 1 addition & 2 deletions lib/journey/formatter.rb
Expand Up @@ -14,6 +14,7 @@ def generate type, name, options, recall = {}, parameterize = nil
constraints = recall.merge options constraints = recall.merge options


match_route(name, constraints) do |route| match_route(name, constraints) do |route|

keys_to_keep = route.parts.reverse.drop_while { |part| keys_to_keep = route.parts.reverse.drop_while { |part|
!options.key?(part) || (options[part] || recall[part]).nil? !options.key?(part) || (options[part] || recall[part]).nil?
} }
Expand All @@ -30,8 +31,6 @@ def generate type, name, options, recall = {}, parameterize = nil


parameterized_parts.keep_if { |_,v| v } parameterized_parts.keep_if { |_,v| v }


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

next unless verify_required_parts!(route, parameterized_parts) next unless verify_required_parts!(route, parameterized_parts)


params = options.dup.delete_if do |key, _| params = options.dup.delete_if do |key, _|
Expand Down
7 changes: 3 additions & 4 deletions test/test_router.rb
Expand Up @@ -302,12 +302,11 @@ def test_nil_path_parts_are_ignored
end end


def test_generate_slash def test_generate_slash
path = Path::Pattern.new '/'
@router.routes.add_route nil, path, {}, {}, {}

params = [ [:controller, "tasks"], params = [ [:controller, "tasks"],
[:action, "show"] ] [: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], {}) path, _ = @formatter.generate(:path_info, nil, Hash[params], {})
assert_equal '/', path assert_equal '/', path
Expand Down

0 comments on commit 06208ad

Please sign in to comment.