Skip to content

Commit

Permalink
Add support and a test for passing segements from route set to a nest…
Browse files Browse the repository at this point in the history
…ed route set
  • Loading branch information
samuelkadolph committed May 13, 2011
1 parent c52eb4b commit 163e869
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/rack/mount/route_set.rb
Expand Up @@ -146,9 +146,13 @@ def call(env)
env[Prefix::KEY] = matches[:path_info].to_s
end

env[@parameters_key] = params
existing_params = env[@parameters_key] || {}
env[@parameters_key] = existing_params.merge(params)

result = route.app.call(env)
return result unless result[1][X_CASCADE] == PASS

env[@parameters_key] = existing_params
end

request || [404, {'Content-Type' => 'text/html', 'X-Cascade' => 'pass'}, ['Not Found']]
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/basic_set_map_19.rb
Expand Up @@ -95,6 +95,7 @@

set.add_route(lambda { |env| [404, {'X-Cascade' => 'pass'}, []] }, { :path_info => %r{^/prefix} })
set.add_route(DefaultSet, { :path_info => %r{^/prefix} }, {}, :prefix)
set.add_route(DefaultSet, { :path_info => %r{^/segmented_prefix/(?<xyz>[a-z0-9]+)} }, {}, :segmented_prefix)

set.add_route(EchoApp, { :path_info => %r{^/prefix2} }, {}, :prefix2)

Expand Down
4 changes: 4 additions & 0 deletions test/test_recognition.rb
Expand Up @@ -349,6 +349,10 @@ def test_path_prefix
assert_equal({}, routing_args)
assert_equal '.foo/bar/1', @env['PATH_INFO']
assert_equal '/prefix2', @env['SCRIPT_NAME']

get '/segmented_prefix/xyz/foo/bar/1'
assert_success
assert_equal({ :controller => 'foo', :action => 'bar', :id => '1', :xyz => 'xyz' }, routing_args)
end

def test_case_insensitive_path
Expand Down
4 changes: 2 additions & 2 deletions test/test_route_set.rb
Expand Up @@ -71,14 +71,14 @@ def test_worst_case
# this number gets smaller. However it may increase if the more
# routes are added to the test fixture.
assert_equal 10, @app.instance_variable_get('@recognition_graph').height
assert_equal 10, @app.instance_variable_get('@generation_graph').height
assert_equal 11, @app.instance_variable_get('@generation_graph').height
end

def test_average_case
# This will probably change wildly, but still an interesting
# statistic to track
assert_equal 7, @app.instance_variable_get('@recognition_graph').average_height.to_i
assert_equal 7, @app.instance_variable_get('@generation_graph').average_height.to_i
assert_equal 8, @app.instance_variable_get('@generation_graph').average_height.to_i
end

private
Expand Down

0 comments on commit 163e869

Please sign in to comment.