From 61579b76616d06ccb8268411421c23fb612e5113 Mon Sep 17 00:00:00 2001 From: Andrew Kaspick Date: Thu, 11 Aug 2011 13:28:31 -0500 Subject: when calling url_for with a hash, additional (likely unwanted) values (such as :host) would be returned in the hash... calling #dup on the hash prevents this --- actionpack/test/dispatch/routing_test.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 1938348375..9685b24c1c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -851,6 +851,18 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + # tests the use of dup in url_for + def test_url_for_with_no_side_effects + # without dup, additional (and possibly unwanted) values will be present in the options (eg. :host) + original_options = {:controller => 'projects', :action => 'status'} + options = original_options.dup + + url_for options + + # verify that the options passed in have not changed from the original ones + assert_equal original_options, options + end + def test_projects_status with_test_routes do assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true) -- cgit v1.2.3 From 019eea4a388442a004287ad2e73772f3fefc7028 Mon Sep 17 00:00:00 2001 From: Pawel Pierzchala Date: Wed, 21 Sep 2011 18:12:55 +0200 Subject: Fix named routes modifying arguments --- actionpack/test/dispatch/routing_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 9685b24c1c..c0b74bc9f9 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -863,6 +863,17 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal original_options, options end + # tests the arguments modification free version of define_hash_access + def test_named_route_with_no_side_effects + original_options = { :host => 'test.host' } + options = original_options.dup + + profile_customer_url("customer_model", options) + + # verify that the options passed in have not changed from the original ones + assert_equal original_options, options + end + def test_projects_status with_test_routes do assert_equal '/projects/status', url_for(:controller => 'projects', :action => 'status', :only_path => true) -- cgit v1.2.3 From 8f863742e34908ed1a9549bb9f984edb58f2b068 Mon Sep 17 00:00:00 2001 From: Diego Carrion Date: Mon, 10 Oct 2011 19:53:42 -0300 Subject: allow shorthand routes with nested optional parameters --- actionpack/test/dispatch/routing_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index c0b74bc9f9..a71ac1bdc1 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -339,6 +339,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end scope '(:locale)', :locale => /en|pl/ do + get "registrations/new" resources :descriptions root :to => 'projects#index' end @@ -1471,6 +1472,16 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_nested_optional_path_shorthand + with_test_routes do + get '/registrations/new' + assert @request.params[:locale].nil? + + get '/en/registrations/new' + assert 'en', @request.params[:locale] + end + end + def test_default_params with_test_routes do get '/inline_pages' -- cgit v1.2.3 From 45ced7e1beb0d996f0471e21f0f88efaf2b26124 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 13 Oct 2011 18:50:23 -0700 Subject: Failing tests for path parameter escaping --- actionpack/test/dispatch/routing_test.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index a71ac1bdc1..a0d2c51a7c 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2528,3 +2528,30 @@ class TestHttpMethods < ActionDispatch::IntegrationTest end end end + +class TestUriPathEscaping < ActionDispatch::IntegrationTest + Routes = ActionDispatch::Routing::RouteSet.new.tap do |app| + app.draw do + match '/:segment' => lambda { |env| + path_params = env['action_dispatch.request.path_parameters'] + [200, { 'Content-Type' => 'text/plain' }, [path_params[:segment]]] + }, :as => :segment + end + end + + include Routes.url_helpers + def app; Routes end + + setup do + @path, @param = '/a%20b%2Fc+d', 'a b/c+d' + end + + test 'escapes generated path parameters' do + assert_equal @path, segment_path(:segment => @param) + end + + test 'unescapes recognized path parameters' do + get @path + assert_equal @param, @response.body + end +end -- cgit v1.2.3 From 401d00d296c0c4dafd0e1103051f6adf0ae56fc5 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 13 Oct 2011 21:42:15 -0700 Subject: Symbol captures may generate multiple path segments, so don't escape / -> %2F. Test splat escaping. --- actionpack/test/dispatch/routing_test.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index a0d2c51a7c..cf22731823 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2536,22 +2536,32 @@ class TestUriPathEscaping < ActionDispatch::IntegrationTest path_params = env['action_dispatch.request.path_parameters'] [200, { 'Content-Type' => 'text/plain' }, [path_params[:segment]]] }, :as => :segment + + match '/*splat' => lambda { |env| + path_params = env['action_dispatch.request.path_parameters'] + [200, { 'Content-Type' => 'text/plain' }, [path_params[:splat]]] + }, :as => :splat end end include Routes.url_helpers def app; Routes end - setup do - @path, @param = '/a%20b%2Fc+d', 'a b/c+d' + test 'escapes generated path segment' do + assert_equal '/a%20b/c+d', segment_path(:segment => 'a b/c+d') + end + + test 'unescapes recognized path segment' do + get '/a%20b%2Fc+d' + assert_equal 'a b/c+d', @response.body end - test 'escapes generated path parameters' do - assert_equal @path, segment_path(:segment => @param) + test 'escapes generated path splat' do + assert_equal '/a%20b/c+d', splat_path(:splat => 'a b/c+d') end - test 'unescapes recognized path parameters' do - get @path - assert_equal @param, @response.body + test 'unescapes recognized path splat' do + get '/a%20b/c+d' + assert_equal 'a b/c+d', @response.body end end -- cgit v1.2.3 From 4589b2419b6c2f6d8b1ea0873999a4d0fa21bdb3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 31 Oct 2011 16:26:11 -0400 Subject: require that all blocks have arity of 2 --- actionpack/test/dispatch/routing_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index cf22731823..66b2263790 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -79,7 +79,7 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match 'sign_in' => "sessions#new" match 'account/modulo/:name', :to => redirect("/%{name}s") - match 'account/proc/:name', :to => redirect {|params| "/#{params[:name].pluralize}" } + match 'account/proc/:name', :to => redirect {|params, req| "/#{params[:name].pluralize}" } match 'account/proc_req' => redirect {|params, req| "/#{req.method}" } match 'account/google' => redirect('http://www.google.com/', :status => 302) -- cgit v1.2.3 From 0809c675ef5831852b7c1aa8497402b2beff5185 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 31 Oct 2011 17:49:20 -0400 Subject: remove the :path feature to redirects, since it cannot work --- actionpack/test/dispatch/routing_test.rb | 33 -------------------------------- 1 file changed, 33 deletions(-) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 66b2263790..c887fe7e6a 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -62,13 +62,8 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest match 'secure', :to => redirect("/secure/login") match 'mobile', :to => redirect(:subdomain => 'mobile') - match 'documentation', :to => redirect(:domain => 'example-documentation.com', :path => '') - match 'new_documentation', :to => redirect(:path => '/documentation/new') match 'super_new_documentation', :to => redirect(:host => 'super-docs.com') - match 'stores/:name', :to => redirect(:subdomain => 'stores', :path => '/%{name}') - match 'stores/:name(*rest)', :to => redirect(:subdomain => 'stores', :path => '/%{name}%{rest}') - match 'youtube_favorites/:youtube_id/:name', :to => redirect(YoutubeFavoritesRedirector) constraints(lambda { |req| true }) do @@ -711,20 +706,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - def test_redirect_hash_with_domain_and_path - with_test_routes do - get '/documentation' - verify_redirect 'http://www.example-documentation.com' - end - end - - def test_redirect_hash_with_path - with_test_routes do - get '/new_documentation' - verify_redirect 'http://www.example.com/documentation/new' - end - end - def test_redirect_hash_with_host with_test_routes do get '/super_new_documentation?section=top' @@ -732,20 +713,6 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end - def test_redirect_hash_path_substitution - with_test_routes do - get '/stores/iernest' - verify_redirect 'http://stores.example.com/iernest' - end - end - - def test_redirect_hash_path_substitution_with_catch_all - with_test_routes do - get '/stores/iernest/products' - verify_redirect 'http://stores.example.com/iernest/products' - end - end - def test_redirect_class with_test_routes do get '/youtube_favorites/oHg5SJYRHA0/rick-rolld' -- cgit v1.2.3 From 99d94f126d05398ec0917d75253ab1548bc54ba3 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Nov 2011 15:53:02 -0200 Subject: Refactoring the redirect method for the router api. --- actionpack/test/dispatch/routing_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'actionpack/test/dispatch/routing_test.rb') diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index c887fe7e6a..19eee379fd 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -2299,6 +2299,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest assert_equal "/forced_collision", routes_forced_collision_path end + def test_redirect_argument_error + routes = Class.new { include ActionDispatch::Routing::Redirection }.new + assert_raises(ArgumentError) { routes.redirect Object.new } + end + def test_explicitly_avoiding_the_named_route assert !respond_to?(:routes_no_collision_path) end -- cgit v1.2.3