2016-08-06 13:16:09 -04:00
|
|
|
require "isolation/abstract_unit"
|
|
|
|
require "rack/test"
|
2009-12-01 22:19:20 -05:00
|
|
|
|
|
|
|
module ApplicationTests
|
2012-01-05 20:30:17 -05:00
|
|
|
class RoutingTest < ActiveSupport::TestCase
|
2009-12-01 22:19:20 -05:00
|
|
|
include ActiveSupport::Testing::Isolation
|
2011-05-08 06:57:07 -04:00
|
|
|
include Rack::Test::Methods
|
2009-12-01 22:19:20 -05:00
|
|
|
|
|
|
|
def setup
|
|
|
|
build_app
|
|
|
|
end
|
|
|
|
|
2011-06-06 08:54:05 -04:00
|
|
|
def teardown
|
|
|
|
teardown_app
|
|
|
|
end
|
|
|
|
|
Use Rails to Render Default Index Page
This is an alternative implementation to #7771 thanks to the advice of @spastorino
Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion.
This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required.
In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated.
The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one).
cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik
ATP Railties and Actionpack.
2012-12-05 14:02:51 -05:00
|
|
|
test "rails/welcome in development" do
|
|
|
|
app("development")
|
|
|
|
get "/"
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
2015-09-27 03:19:20 -04:00
|
|
|
test "rails/info in development" do
|
|
|
|
app("development")
|
2015-09-27 11:39:32 -04:00
|
|
|
get "/rails/info"
|
2015-09-27 03:19:20 -04:00
|
|
|
assert_equal 302, last_response.status
|
|
|
|
end
|
|
|
|
|
2012-05-23 15:42:28 -04:00
|
|
|
test "rails/info/routes in development" do
|
|
|
|
app("development")
|
|
|
|
get "/rails/info/routes"
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
2010-08-09 14:48:31 -04:00
|
|
|
test "rails/info/properties in development" do
|
|
|
|
app("development")
|
|
|
|
get "/rails/info/properties"
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
2016-06-18 04:46:44 -04:00
|
|
|
test "/rails/info routes are accessible with globbing route present" do
|
|
|
|
app("development")
|
|
|
|
|
|
|
|
app_file "config/routes.rb", <<-RUBY
|
|
|
|
Rails.application.routes.draw do
|
|
|
|
get '*foo', to: 'foo#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
get "/rails/info"
|
|
|
|
assert_equal 302, last_response.status
|
|
|
|
|
|
|
|
get "rails/info/routes"
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
|
|
|
|
get "rails/info/properties"
|
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
|
|
|
|
Use Rails to Render Default Index Page
This is an alternative implementation to #7771 thanks to the advice of @spastorino
Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion.
This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required.
In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated.
The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one).
cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik
ATP Railties and Actionpack.
2012-12-05 14:02:51 -05:00
|
|
|
test "root takes precedence over internal welcome controller" do
|
|
|
|
app("development")
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_welcome get("/")
|
Use Rails to Render Default Index Page
This is an alternative implementation to #7771 thanks to the advice of @spastorino
Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion.
This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required.
In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated.
The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one).
cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik
ATP Railties and Actionpack.
2012-12-05 14:02:51 -05:00
|
|
|
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "foo"
|
Use Rails to Render Default Index Page
This is an alternative implementation to #7771 thanks to the advice of @spastorino
Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion.
This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required.
In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated.
The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one).
cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik
ATP Railties and Actionpack.
2012-12-05 14:02:51 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
Use Rails to Render Default Index Page
This is an alternative implementation to #7771 thanks to the advice of @spastorino
Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion.
This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required.
In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated.
The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one).
cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik
ATP Railties and Actionpack.
2012-12-05 14:02:51 -05:00
|
|
|
root to: "foo#index"
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/"
|
|
|
|
assert_equal "foo", last_response.body
|
Use Rails to Render Default Index Page
This is an alternative implementation to #7771 thanks to the advice of @spastorino
Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion.
This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required.
In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated.
The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one).
cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik
ATP Railties and Actionpack.
2012-12-05 14:02:51 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "rails/welcome in production" do
|
|
|
|
app("production")
|
|
|
|
get "/"
|
2013-07-22 11:19:07 -04:00
|
|
|
assert_equal 404, last_response.status
|
Use Rails to Render Default Index Page
This is an alternative implementation to #7771 thanks to the advice of @spastorino
Rails is a dynamic framework that serves a static index.html by default. One of my first questions ever on IRC was solved by simply deleting my public/index.html file. This file is a source of confusion when starting as it over-rides any set "root" in the routes yet it itself is not listed in the routes. By making the page dynamic by default we can eliminate this confusion.
This PR moves the static index page to an internal controller/route/view similar to `rails/info`. When someone starts a rails server, if no root is defined, this route will take over and the "dynamic" index page from rails/welcome_controller will be rendered. These routes are only added in development. If a developer defines a root in their routes, it automatically takes precedence over this route and will be rendered, with no deleting of files required.
In addition to removing this source of confusion for new devs, we can now use Rails view helpers to build and render this page. While not the primary intent, the added value of "dogfooding" should not be under-estimated.
The prior PR #7771 had push-back since it introduced developer facing files. This PR solves all of the same problems, but does not have any new developer facing files (it actually removes one).
cc/ @wsouto, @dickeyxxx, @tyre, @ryanb, @josevalim, @maxim, @subdigital, @steveklabnik
ATP Railties and Actionpack.
2012-12-05 14:02:51 -05:00
|
|
|
end
|
|
|
|
|
2015-09-27 03:19:20 -04:00
|
|
|
test "rails/info in production" do
|
|
|
|
app("production")
|
|
|
|
get "/rails/info"
|
|
|
|
assert_equal 404, last_response.status
|
|
|
|
end
|
|
|
|
|
2012-05-23 15:42:28 -04:00
|
|
|
test "rails/info/routes in production" do
|
|
|
|
app("production")
|
|
|
|
get "/rails/info/routes"
|
|
|
|
assert_equal 404, last_response.status
|
|
|
|
end
|
|
|
|
|
2010-08-09 14:48:31 -04:00
|
|
|
test "rails/info/properties in production" do
|
|
|
|
app("production")
|
|
|
|
get "/rails/info/properties"
|
|
|
|
assert_equal 404, last_response.status
|
|
|
|
end
|
|
|
|
|
|
|
|
test "simple controller" do
|
|
|
|
simple_controller
|
2009-12-21 18:47:03 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "foo", last_response.body
|
2010-08-09 14:48:31 -04:00
|
|
|
end
|
|
|
|
|
2010-01-26 07:57:11 -05:00
|
|
|
test "simple controller with helper" do
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
2012-10-14 06:03:39 -04:00
|
|
|
render inline: "<%= foo_or_bar? %>"
|
2010-01-26 07:57:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "app/helpers/bar_helper.rb", <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
module BarHelper
|
|
|
|
def foo_or_bar?
|
|
|
|
"bar"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get ':controller(/:action)'
|
2010-01-26 07:57:11 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "bar", last_response.body
|
2010-01-26 07:57:11 -05:00
|
|
|
end
|
|
|
|
|
2010-06-17 07:48:02 -04:00
|
|
|
test "mount rack app" do
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
mount lambda { |env| [200, {}, [env["PATH_INFO"]]] }, at: "/blog"
|
2010-06-17 07:48:02 -04:00
|
|
|
# The line below is required because mount sometimes
|
|
|
|
# fails when a resource route is added.
|
|
|
|
resource :user
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/blog/archives"
|
|
|
|
assert_equal "/archives", last_response.body
|
2010-06-17 07:48:02 -04:00
|
|
|
end
|
|
|
|
|
2014-11-28 14:58:10 -05:00
|
|
|
test "mount named rack app" do
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: my_blog_path
|
2014-11-28 14:58:10 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2014-11-28 14:58:10 -05:00
|
|
|
Rails.application.routes.draw do
|
|
|
|
mount lambda { |env| [200, {}, [env["PATH_INFO"]]] }, at: "/blog", as: "my_blog"
|
|
|
|
get '/foo' => 'foo#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "/blog", last_response.body
|
2014-11-28 14:58:10 -05:00
|
|
|
end
|
|
|
|
|
2009-12-01 22:19:20 -05:00
|
|
|
test "multiple controllers" do
|
|
|
|
controller :foo, <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-01 22:19:20 -05:00
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "foo"
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
controller :bar, <<-RUBY
|
|
|
|
class BarController < ActionController::Base
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "bar"
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get ':controller(/:action)'
|
2009-12-21 18:47:03 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "foo", last_response.body
|
2009-12-01 22:19:20 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/bar"
|
|
|
|
assert_equal "bar", last_response.body
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
test "nested controller" do
|
2016-08-06 13:16:09 -04:00
|
|
|
controller "foo", <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-01 22:19:20 -05:00
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "foo"
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
controller "admin/foo", <<-RUBY
|
2009-12-01 22:19:20 -05:00
|
|
|
module Admin
|
2010-01-26 07:57:11 -05:00
|
|
|
class FooController < ApplicationController
|
2009-12-01 22:19:20 -05:00
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "admin::foo"
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get 'admin/foo', to: 'admin/foo#index'
|
|
|
|
get 'foo', to: 'foo#index'
|
2009-12-21 18:47:03 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "foo", last_response.body
|
2009-12-01 22:19:20 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/admin/foo"
|
|
|
|
assert_equal "admin::foo", last_response.body
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
2009-12-14 17:51:13 -05:00
|
|
|
|
2010-10-02 11:42:36 -04:00
|
|
|
test "routes appending blocks" do
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get ':controller/:action'
|
2010-09-17 15:05:40 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
add_to_config <<-R
|
|
|
|
routes.append do
|
2012-04-24 23:32:09 -04:00
|
|
|
get '/win' => lambda { |e| [200, {'Content-Type'=>'text/plain'}, ['WIN']] }
|
2010-09-17 15:05:40 -04:00
|
|
|
end
|
|
|
|
R
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app "development"
|
2010-09-17 15:05:40 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/win"
|
|
|
|
assert_equal "WIN", last_response.body
|
2010-09-17 15:05:40 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-R
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-04-24 23:32:09 -04:00
|
|
|
get 'lol' => 'hello#index'
|
2010-09-17 15:05:40 -04:00
|
|
|
end
|
|
|
|
R
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/win"
|
|
|
|
assert_equal "WIN", last_response.body
|
2010-09-17 15:05:40 -04:00
|
|
|
end
|
|
|
|
|
2016-01-20 10:03:10 -05:00
|
|
|
{
|
|
|
|
"development" => ["baz", "http://www.apple.com"],
|
|
|
|
"production" => ["bar", "http://www.microsoft.com"]
|
|
|
|
}.each do |mode, (expected_action, expected_url)|
|
2010-08-09 14:48:31 -04:00
|
|
|
test "reloads routes when configuration is changed in #{mode}" do
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def bar
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "bar"
|
2010-08-09 14:48:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def baz
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "baz"
|
2010-08-09 14:48:31 -04:00
|
|
|
end
|
2016-01-20 10:03:10 -05:00
|
|
|
|
|
|
|
def custom
|
|
|
|
render plain: custom_url
|
|
|
|
end
|
2009-12-15 11:48:56 -05:00
|
|
|
end
|
2010-08-09 14:48:31 -04:00
|
|
|
RUBY
|
2009-12-15 11:48:56 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get 'foo', to: 'foo#bar'
|
2016-01-20 10:03:10 -05:00
|
|
|
get 'custom', to: 'foo#custom'
|
|
|
|
|
|
|
|
url_helper(:custom) { "http://www.microsoft.com" }
|
2009-12-15 11:48:56 -05:00
|
|
|
end
|
2010-08-09 14:48:31 -04:00
|
|
|
RUBY
|
2009-12-15 11:48:56 -05:00
|
|
|
|
2010-08-09 14:48:31 -04:00
|
|
|
app(mode)
|
2009-12-15 11:48:56 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "bar", last_response.body
|
2009-12-15 11:48:56 -05:00
|
|
|
|
2016-01-20 10:03:10 -05:00
|
|
|
get "/custom"
|
|
|
|
assert_equal "http://www.microsoft.com", last_response.body
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get 'foo', to: 'foo#baz'
|
2016-01-20 10:03:10 -05:00
|
|
|
get 'custom', to: 'foo#custom'
|
|
|
|
|
|
|
|
url_helper(:custom) { "http://www.apple.com" }
|
2010-08-09 14:48:31 -04:00
|
|
|
end
|
|
|
|
RUBY
|
2009-12-15 11:48:56 -05:00
|
|
|
|
2010-08-09 14:48:31 -04:00
|
|
|
sleep 0.1
|
2009-12-23 20:01:07 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
2016-01-20 10:03:10 -05:00
|
|
|
assert_equal expected_action, last_response.body
|
|
|
|
|
|
|
|
get "/custom"
|
|
|
|
assert_equal expected_url, last_response.body
|
2010-08-09 14:48:31 -04:00
|
|
|
end
|
2009-12-15 11:48:56 -05:00
|
|
|
end
|
2010-01-21 11:30:17 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "routes are loaded just after initialization" do
|
2010-09-02 06:54:16 -04:00
|
|
|
require "#{app_path}/config/application"
|
|
|
|
|
2010-10-02 11:42:36 -04:00
|
|
|
# Create the rack app just inside after initialize callback
|
|
|
|
ActiveSupport.on_load(:after_initialize) do
|
|
|
|
::InitializeRackApp = lambda { |env| [200, {}, ["InitializeRackApp"]] }
|
|
|
|
end
|
2010-09-11 06:58:37 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-10-14 06:03:39 -04:00
|
|
|
get 'foo', to: ::InitializeRackApp
|
2010-09-02 06:54:16 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
2010-09-02 06:54:16 -04:00
|
|
|
assert_equal "InitializeRackApp", last_response.body
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "reload_routes! is part of Rails.application API" do
|
2010-10-02 11:45:26 -04:00
|
|
|
app("development")
|
|
|
|
assert_nothing_raised do
|
|
|
|
Rails.application.reload_routes!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-04-17 14:20:12 -04:00
|
|
|
def test_root_path
|
2016-08-06 13:16:09 -04:00
|
|
|
app("development")
|
2013-04-17 14:20:12 -04:00
|
|
|
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "foo"
|
2013-04-17 14:20:12 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2013-04-17 14:20:12 -04:00
|
|
|
get 'foo', :to => 'foo#index'
|
|
|
|
root :to => 'foo#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
remove_file "public/index.html"
|
2013-04-17 14:20:12 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/"
|
|
|
|
assert_equal "foo", last_response.body
|
2013-04-17 14:20:12 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "routes are added and removed when reloading" do
|
|
|
|
app("development")
|
2012-12-14 08:15:57 -05:00
|
|
|
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "foo"
|
2012-12-14 08:15:57 -05:00
|
|
|
end
|
2016-01-20 10:03:10 -05:00
|
|
|
|
|
|
|
def custom
|
|
|
|
render text: custom_url
|
|
|
|
end
|
2012-12-14 08:15:57 -05:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
controller :bar, <<-RUBY
|
|
|
|
class BarController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "bar"
|
2012-12-14 08:15:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-12-14 08:15:57 -05:00
|
|
|
get 'foo', to: 'foo#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "foo", last_response.body
|
|
|
|
assert_equal "/foo", Rails.application.routes.url_helpers.foo_path
|
2012-12-14 08:15:57 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/bar"
|
2012-12-14 08:15:57 -05:00
|
|
|
assert_equal 404, last_response.status
|
|
|
|
assert_raises NoMethodError do
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_equal "/bar", Rails.application.routes.url_helpers.bar_path
|
2012-12-14 08:15:57 -05:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-12-14 08:15:57 -05:00
|
|
|
get 'foo', to: 'foo#index'
|
|
|
|
get 'bar', to: 'bar#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
Rails.application.reload_routes!
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "foo", last_response.body
|
|
|
|
assert_equal "/foo", Rails.application.routes.url_helpers.foo_path
|
2012-12-14 08:15:57 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/bar"
|
|
|
|
assert_equal "bar", last_response.body
|
|
|
|
assert_equal "/bar", Rails.application.routes.url_helpers.bar_path
|
2012-12-14 08:15:57 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2012-12-14 08:15:57 -05:00
|
|
|
get 'foo', to: 'foo#index'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
Rails.application.reload_routes!
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/foo"
|
|
|
|
assert_equal "foo", last_response.body
|
|
|
|
assert_equal "/foo", Rails.application.routes.url_helpers.foo_path
|
2012-12-14 08:15:57 -05:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/bar"
|
2012-12-14 08:15:57 -05:00
|
|
|
assert_equal 404, last_response.status
|
|
|
|
assert_raises NoMethodError do
|
2016-08-06 13:16:09 -04:00
|
|
|
assert_equal "/bar", Rails.application.routes.url_helpers.bar_path
|
2012-12-14 08:15:57 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "named routes are cleared when reloading" do
|
|
|
|
app("development")
|
2013-07-21 12:10:34 -04:00
|
|
|
|
|
|
|
controller :foo, <<-RUBY
|
|
|
|
class FooController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "foo"
|
2013-07-21 12:10:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
controller :bar, <<-RUBY
|
|
|
|
class BarController < ApplicationController
|
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: "bar"
|
2013-07-21 12:10:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-07-21 12:10:34 -04:00
|
|
|
Rails.application.routes.draw do
|
|
|
|
get ':locale/foo', to: 'foo#index', as: 'foo'
|
2016-01-20 10:03:10 -05:00
|
|
|
url_helper(:microsoft) { 'http://www.microsoft.com' }
|
2013-07-21 12:10:34 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/en/foo"
|
|
|
|
assert_equal "foo", last_response.body
|
2016-08-06 13:38:55 -04:00
|
|
|
assert_equal "/en/foo", Rails.application.routes.url_helpers.foo_path(locale: "en")
|
2016-01-20 10:03:10 -05:00
|
|
|
assert_equal "http://www.microsoft.com", Rails.application.routes.url_helpers.microsoft_url
|
2013-07-21 12:10:34 -04:00
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-07-21 12:10:34 -04:00
|
|
|
Rails.application.routes.draw do
|
|
|
|
get ':locale/bar', to: 'bar#index', as: 'foo'
|
2016-01-20 10:03:10 -05:00
|
|
|
url_helper(:apple) { 'http://www.apple.com' }
|
2013-07-21 12:10:34 -04:00
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
|
|
|
Rails.application.reload_routes!
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/en/foo"
|
2013-07-21 12:10:34 -04:00
|
|
|
assert_equal 404, last_response.status
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/en/bar"
|
|
|
|
assert_equal "bar", last_response.body
|
2016-08-06 13:38:55 -04:00
|
|
|
assert_equal "/en/bar", Rails.application.routes.url_helpers.foo_path(locale: "en")
|
2016-01-20 10:03:10 -05:00
|
|
|
assert_equal "http://www.apple.com", Rails.application.routes.url_helpers.apple_url
|
|
|
|
|
|
|
|
assert_raises NoMethodError do
|
|
|
|
assert_equal "http://www.microsoft.com", Rails.application.routes.url_helpers.microsoft_url
|
|
|
|
end
|
2013-07-21 12:10:34 -04:00
|
|
|
end
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
test "resource routing with irregular inflection" do
|
|
|
|
app_file "config/initializers/inflection.rb", <<-RUBY
|
2010-01-21 11:30:17 -05:00
|
|
|
ActiveSupport::Inflector.inflections do |inflect|
|
|
|
|
inflect.irregular 'yazi', 'yazilar'
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
app_file "config/routes.rb", <<-RUBY
|
2013-06-03 23:57:01 -04:00
|
|
|
Rails.application.routes.draw do
|
2010-01-21 11:30:17 -05:00
|
|
|
resources :yazilar
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
controller "yazilar", <<-RUBY
|
2010-01-26 07:57:11 -05:00
|
|
|
class YazilarController < ApplicationController
|
2010-01-21 11:30:17 -05:00
|
|
|
def index
|
2016-05-21 08:49:38 -04:00
|
|
|
render plain: 'yazilar#index'
|
2010-01-21 11:30:17 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
RUBY
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/yazilars"
|
2010-01-21 11:30:17 -05:00
|
|
|
assert_equal 404, last_response.status
|
|
|
|
|
2016-08-06 13:16:09 -04:00
|
|
|
get "/yazilar"
|
2010-01-21 11:30:17 -05:00
|
|
|
assert_equal 200, last_response.status
|
|
|
|
end
|
2009-12-01 22:19:20 -05:00
|
|
|
end
|
|
|
|
end
|