diff options
Diffstat (limited to 'actionpack/test/dispatch/routing')
-rw-r--r-- | actionpack/test/dispatch/routing/concerns_test.rb | 4 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing/inspector_test.rb | 129 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing/ipv6_redirect_test.rb | 23 | ||||
-rw-r--r-- | actionpack/test/dispatch/routing/route_set_test.rb | 72 |
4 files changed, 129 insertions, 99 deletions
diff --git a/actionpack/test/dispatch/routing/concerns_test.rb b/actionpack/test/dispatch/routing/concerns_test.rb index 7ef513b0c8..2d71c37562 100644 --- a/actionpack/test/dispatch/routing/concerns_test.rb +++ b/actionpack/test/dispatch/routing/concerns_test.rb @@ -1,4 +1,6 @@ -require 'abstract_unit' +require "abstract_unit" + +class ReviewsController < ResourcesController; end class RoutingConcernsTest < ActionDispatch::IntegrationTest class Reviewable diff --git a/actionpack/test/dispatch/routing/inspector_test.rb b/actionpack/test/dispatch/routing/inspector_test.rb index f72a87b994..a4babf8554 100644 --- a/actionpack/test/dispatch/routing/inspector_test.rb +++ b/actionpack/test/dispatch/routing/inspector_test.rb @@ -1,6 +1,6 @@ -require 'abstract_unit' -require 'rails/engine' -require 'action_dispatch/routing/inspector' +require "abstract_unit" +require "rails/engine" +require "action_dispatch/routing/inspector" class MountedRackApp def self.call(env) @@ -30,11 +30,11 @@ module ActionDispatch end end engine.routes.draw do - get '/cart', :to => 'cart#show' + get "/cart", to: "cart#show" end output = draw do - get '/custom/assets', :to => 'custom_assets#show' + get "/custom/assets", to: "custom_assets#show" mount engine => "/blog", :as => "blog" end @@ -71,7 +71,7 @@ module ActionDispatch def test_cart_inspect output = draw do - get '/cart', :to => 'cart#show' + get "/cart", to: "cart#show" end assert_equal [ @@ -82,7 +82,7 @@ module ActionDispatch def test_articles_inspect_with_multiple_verbs output = draw do - match 'articles/:id', to: 'articles#update', via: [:put, :patch] + match "articles/:id", to: "articles#update", via: [:put, :patch] end assert_equal [ @@ -93,7 +93,7 @@ module ActionDispatch def test_inspect_shows_custom_assets output = draw do - get '/custom/assets', :to => 'custom_assets#show' + get "/custom/assets", to: "custom_assets#show" end assert_equal [ @@ -122,7 +122,7 @@ module ActionDispatch def test_inspect_routes_shows_root_route output = draw do - root :to => 'pages#main' + root to: "pages#main" end assert_equal [ @@ -133,7 +133,9 @@ module ActionDispatch def test_inspect_routes_shows_dynamic_action_route output = draw do - get 'api/:action' => 'api' + ActiveSupport::Deprecation.silence do + get "api/:action" => "api" + end end assert_equal [ @@ -144,7 +146,9 @@ module ActionDispatch def test_inspect_routes_shows_controller_and_action_only_route output = draw do - get ':controller/:action' + ActiveSupport::Deprecation.silence do + get ":controller/:action" + end end assert_equal [ @@ -155,7 +159,9 @@ module ActionDispatch def test_inspect_routes_shows_controller_and_action_route_with_constraints output = draw do - get ':controller(/:action(/:id))', :id => /\d+/ + ActiveSupport::Deprecation.silence do + get ":controller(/:action(/:id))", id: /\d+/ + end end assert_equal [ @@ -164,20 +170,20 @@ module ActionDispatch ], output end - def test_rake_routes_shows_route_with_defaults + def test_rails_routes_shows_route_with_defaults output = draw do - get 'photos/:id' => 'photos#show', :defaults => {:format => 'jpg'} + get "photos/:id" => "photos#show", :defaults => { format: "jpg" } end assert_equal [ "Prefix Verb URI Pattern Controller#Action", - %Q[ GET /photos/:id(.:format) photos#show {:format=>"jpg"}] + ' GET /photos/:id(.:format) photos#show {:format=>"jpg"}' ], output end - def test_rake_routes_shows_route_with_constraints + def test_rails_routes_shows_route_with_constraints output = draw do - get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ + get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/ end assert_equal [ @@ -186,15 +192,15 @@ module ActionDispatch ], output end - def test_rake_routes_shows_routes_with_dashes + def test_rails_routes_shows_routes_with_dashes output = draw do - get 'about-us' => 'pages#about_us' - get 'our-work/latest' + get "about-us" => "pages#about_us" + get "our-work/latest" resources :photos, only: [:show] do - get 'user-favorites', on: :collection - get 'preview-photo', on: :member - get 'summary-text' + get "user-favorites", on: :collection + get "preview-photo", on: :member + get "summary-text" end end @@ -209,9 +215,9 @@ module ActionDispatch ], output end - def test_rake_routes_shows_route_with_rack_app + def test_rails_routes_shows_route_with_rack_app output = draw do - get 'foo/:id' => MountedRackApp, :id => /[A-Z]\d{5}/ + get "foo/:id" => MountedRackApp, :id => /[A-Z]\d{5}/ end assert_equal [ @@ -220,9 +226,9 @@ module ActionDispatch ], output end - def test_rake_routes_shows_named_route_with_mounted_rack_app + def test_rails_routes_shows_named_route_with_mounted_rack_app output = draw do - mount MountedRackApp => '/foo' + mount MountedRackApp => "/foo" end assert_equal [ @@ -231,9 +237,9 @@ module ActionDispatch ], output end - def test_rake_routes_shows_overridden_named_route_with_mounted_rack_app_with_name + def test_rails_routes_shows_overridden_named_route_with_mounted_rack_app_with_name output = draw do - mount MountedRackApp => '/foo', as: 'blog' + mount MountedRackApp => "/foo", as: "blog" end assert_equal [ @@ -242,7 +248,7 @@ module ActionDispatch ], output end - def test_rake_routes_shows_route_with_rack_app_nested_with_dynamic_constraints + def test_rails_routes_shows_route_with_rack_app_nested_with_dynamic_constraints constraint = Class.new do def inspect "( my custom constraint )" @@ -250,8 +256,8 @@ module ActionDispatch end output = draw do - scope :constraint => constraint.new do - mount MountedRackApp => '/foo' + scope constraint: constraint.new do + mount MountedRackApp => "/foo" end end @@ -261,18 +267,18 @@ module ActionDispatch ], output end - def test_rake_routes_dont_show_app_mounted_in_assets_prefix + def test_rails_routes_dont_show_app_mounted_in_assets_prefix output = draw do - get '/sprockets' => MountedRackApp + get "/sprockets" => MountedRackApp end assert_no_match(/MountedRackApp/, output.first) assert_no_match(/\/sprockets/, output.first) end - def test_rake_routes_shows_route_defined_in_under_assets_prefix + def test_rails_routes_shows_route_defined_in_under_assets_prefix output = draw do - scope '/sprockets' do - get '/foo' => 'foo#bar' + scope "/sprockets" do + get "/foo" => "foo#bar" end end assert_equal [ @@ -283,9 +289,9 @@ module ActionDispatch def test_redirect output = draw do - get "/foo" => redirect("/foo/bar"), :constraints => { :subdomain => "admin" } + get "/foo" => redirect("/foo/bar"), :constraints => { subdomain: "admin" } get "/bar" => redirect(path: "/foo/bar", status: 307) - get "/foobar" => redirect{ "/foo/bar" } + get "/foobar" => redirect { "/foo/bar" } end assert_equal [ @@ -297,7 +303,7 @@ module ActionDispatch end def test_routes_can_be_filtered - output = draw('posts') do + output = draw("posts") do resources :articles resources :posts end @@ -314,7 +320,7 @@ module ActionDispatch end def test_routes_can_be_filtered_with_namespaced_controllers - output = draw('admin/posts') do + output = draw("admin/posts") do resources :articles namespace :admin do resources :posts @@ -332,21 +338,22 @@ module ActionDispatch " DELETE /admin/posts/:id(.:format) admin/posts#destroy"], output end - def test_regression_route_with_controller_regexp output = draw do - get ':controller(/:action)', controller: /api\/[^\/]+/, format: false + ActiveSupport::Deprecation.silence do + get ":controller(/:action)", controller: /api\/[^\/]+/, format: false + end end assert_equal ["Prefix Verb URI Pattern Controller#Action", - " GET /:controller(/:action) (?-mix:api\\/[^\\/]+)#:action"], output + " GET /:controller(/:action) :controller#:action"], output end def test_inspect_routes_shows_resources_route_when_assets_disabled @set = ActionDispatch::Routing::RouteSet.new output = draw do - get '/cart', to: 'cart#show' + get "/cart", to: "cart#show" end assert_equal [ @@ -356,8 +363,8 @@ module ActionDispatch end def test_routes_with_undefined_filter - output = draw(controller: 'Rails::MissingController') do - get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ + output = draw(controller: "Rails::MissingController") do + get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/ end assert_equal [ @@ -367,8 +374,8 @@ module ActionDispatch end def test_no_routes_matched_filter - output = draw('rails/dummy') do - get 'photos/:id' => 'photos#show', :id => /[A-Z]\d{5}/ + output = draw("rails/dummy") do + get "photos/:id" => "photos#show", :id => /[A-Z]\d{5}/ end assert_equal [ @@ -378,7 +385,7 @@ module ActionDispatch end def test_no_routes_were_defined - output = draw('Rails::DummyController') {} + output = draw("Rails::DummyController") {} assert_equal [ "You don't have any routes defined!", @@ -389,6 +396,28 @@ module ActionDispatch ], output end + def test_displaying_routes_for_internal_engines + engine = Class.new(Rails::Engine) do + def self.inspect + "Blog::Engine" + end + end + engine.routes.draw do + get "/cart", to: "cart#show" + post "/cart", to: "cart#create" + patch "/cart", to: "cart#update" + end + + output = draw do + get "/custom/assets", to: "custom_assets#show" + mount engine => "/blog", as: "blog", internal: true + end + + assert_equal [ + " Prefix Verb URI Pattern Controller#Action", + "custom_assets GET /custom/assets(.:format) custom_assets#show", + ], output + end end end end diff --git a/actionpack/test/dispatch/routing/ipv6_redirect_test.rb b/actionpack/test/dispatch/routing/ipv6_redirect_test.rb index f1b2e8cfc7..4987ed84e4 100644 --- a/actionpack/test/dispatch/routing/ipv6_redirect_test.rb +++ b/actionpack/test/dispatch/routing/ipv6_redirect_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" class IPv6IntegrationTest < ActionDispatch::IntegrationTest Routes = ActionDispatch::Routing::RouteSet.new @@ -7,17 +7,17 @@ class IPv6IntegrationTest < ActionDispatch::IntegrationTest class ::BadRouteRequestController < ActionController::Base include Routes.url_helpers def index - render :text => foo_path + render text: foo_path end def foo - redirect_to :action => :index + redirect_to action: :index end end Routes.draw do - get "/", :to => 'bad_route_request#index', :as => :index - get "/foo", :to => "bad_route_request#foo", :as => :foo + get "/", to: "bad_route_request#index", as: :index + get "/foo", to: "bad_route_request#foo", as: :foo end def _routes @@ -32,14 +32,13 @@ class IPv6IntegrationTest < ActionDispatch::IntegrationTest test "bad IPv6 redirection" do # def test_simple_redirect request_env = { - 'REMOTE_ADDR' => 'fd07:2fa:6cff:2112:225:90ff:fec7:22aa', - 'HTTP_HOST' => '[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000', - 'SERVER_NAME' => '[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]', - 'SERVER_PORT' => 3000 } + "REMOTE_ADDR" => "fd07:2fa:6cff:2112:225:90ff:fec7:22aa", + "HTTP_HOST" => "[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000", + "SERVER_NAME" => "[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]", + "SERVER_PORT" => 3000 } - get '/foo', env: request_env + get "/foo", env: request_env assert_response :redirect - assert_equal 'http://[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000/', redirect_to_url + assert_equal "http://[fd07:2fa:6cff:2112:225:90ff:fec7:22aa]:3000/", redirect_to_url end - end diff --git a/actionpack/test/dispatch/routing/route_set_test.rb b/actionpack/test/dispatch/routing/route_set_test.rb index 9327fe12c6..ace35dda53 100644 --- a/actionpack/test/dispatch/routing/route_set_test.rb +++ b/actionpack/test/dispatch/routing/route_set_test.rb @@ -1,4 +1,4 @@ -require 'abstract_unit' +require "abstract_unit" module ActionDispatch module Routing @@ -9,7 +9,7 @@ module ActionDispatch end def call(env) - [ 200, { 'Content-Type' => 'text/plain' }, [response] ] + [ 200, { "Content-Type" => "text/plain" }, [response] ] end end @@ -21,7 +21,7 @@ module ActionDispatch assert empty? draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end assert_not empty? @@ -29,101 +29,101 @@ module ActionDispatch test "url helpers are added when route is added" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal '/foo', url_helpers.foo_path + assert_equal "/foo", url_helpers.foo_path assert_raises NoMethodError do - assert_equal '/bar', url_helpers.bar_path + assert_equal "/bar", url_helpers.bar_path end draw do - get 'foo', to: SimpleApp.new('foo#index') - get 'bar', to: SimpleApp.new('bar#index') + get "foo", to: SimpleApp.new("foo#index") + get "bar", to: SimpleApp.new("bar#index") end - assert_equal '/foo', url_helpers.foo_path - assert_equal '/bar', url_helpers.bar_path + assert_equal "/foo", url_helpers.foo_path + assert_equal "/bar", url_helpers.bar_path end test "url helpers are updated when route is updated" do draw do - get 'bar', to: SimpleApp.new('bar#index'), as: :bar + get "bar", to: SimpleApp.new("bar#index"), as: :bar end - assert_equal '/bar', url_helpers.bar_path + assert_equal "/bar", url_helpers.bar_path draw do - get 'baz', to: SimpleApp.new('baz#index'), as: :bar + get "baz", to: SimpleApp.new("baz#index"), as: :bar end - assert_equal '/baz', url_helpers.bar_path + assert_equal "/baz", url_helpers.bar_path end test "url helpers are removed when route is removed" do draw do - get 'foo', to: SimpleApp.new('foo#index') - get 'bar', to: SimpleApp.new('bar#index') + get "foo", to: SimpleApp.new("foo#index") + get "bar", to: SimpleApp.new("bar#index") end - assert_equal '/foo', url_helpers.foo_path - assert_equal '/bar', url_helpers.bar_path + assert_equal "/foo", url_helpers.foo_path + assert_equal "/bar", url_helpers.bar_path draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal '/foo', url_helpers.foo_path + assert_equal "/foo", url_helpers.foo_path assert_raises NoMethodError do - assert_equal '/bar', url_helpers.bar_path + assert_equal "/bar", url_helpers.bar_path end end test "only_path: true with *_url and no :host option" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal '/foo', url_helpers.foo_url(only_path: true) + assert_equal "/foo", url_helpers.foo_url(only_path: true) end test "only_path: false with *_url and no :host option" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end assert_raises ArgumentError do - assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false) + assert_equal "http://example.com/foo", url_helpers.foo_url(only_path: false) end end test "only_path: false with *_url and local :host option" do draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false, host: 'example.com') + assert_equal "http://example.com/foo", url_helpers.foo_url(only_path: false, host: "example.com") end test "only_path: false with *_url and global :host option" do - @set.default_url_options = { host: 'example.com' } + @set.default_url_options = { host: "example.com" } draw do - get 'foo', to: SimpleApp.new('foo#index') + get "foo", to: SimpleApp.new("foo#index") end - assert_equal 'http://example.com/foo', url_helpers.foo_url(only_path: false) + assert_equal "http://example.com/foo", url_helpers.foo_url(only_path: false) end test "explicit keys win over implicit keys" do draw do resources :foo do - resources :bar, to: SimpleApp.new('foo#show') + resources :bar, to: SimpleApp.new("foo#show") end end - assert_equal '/foo/1/bar/2', url_helpers.foo_bar_path(1, 2) - assert_equal '/foo/1/bar/2', url_helpers.foo_bar_path(2, foo_id: 1) + assert_equal "/foo/1/bar/2", url_helpers.foo_bar_path(1, 2) + assert_equal "/foo/1/bar/2", url_helpers.foo_bar_path(2, foo_id: 1) end test "having an optional scope with resources" do @@ -133,9 +133,9 @@ module ActionDispatch end end - assert_equal '/users/1', url_helpers.user_path(1) - assert_equal '/users/1', url_helpers.user_path(1, foo: nil) - assert_equal '/a/users/1', url_helpers.user_path(1, foo: 'a') + assert_equal "/users/1", url_helpers.user_path(1) + assert_equal "/users/1", url_helpers.user_path(1, foo: nil) + assert_equal "/a/users/1", url_helpers.user_path(1, foo: "a") end private |