diff options
Diffstat (limited to 'railties/test/application/routing_test.rb')
-rw-r--r-- | railties/test/application/routing_test.rb | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 204f43a442..4560dcec69 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -166,6 +166,91 @@ module ApplicationTests assert_equal 'WIN', last_response.body end + test "routes drawing from config/routes" do + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + draw :external + end + RUBY + + app_file 'config/routes/external.rb', <<-RUBY + get ':controller/:action' + RUBY + + controller :success, <<-RUBY + class SuccessController < ActionController::Base + def index + render :text => "success!" + end + end + RUBY + + app 'development' + get '/success/index' + assert_equal 'success!', last_response.body + end + + {"development" => "baz", "production" => "bar"}.each do |mode, expected| + test "reloads routes when external configuration is changed in #{mode}" do + controller :foo, <<-RUBY + class FooController < ApplicationController + def bar + render :text => "bar" + end + + def baz + render :text => "baz" + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + draw :external + end + RUBY + + app_file 'config/routes/external.rb', <<-RUBY + get 'foo', :to => 'foo#bar' + RUBY + + app(mode) + + get '/foo' + assert_equal 'bar', last_response.body + + app_file 'config/routes/external.rb', <<-RUBY + get 'foo', :to => 'foo#baz' + RUBY + + sleep 0.1 + + get '/foo' + assert_equal expected, last_response.body + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + draw :external + draw :other_external + end + RUBY + + app_file 'config/routes/other_external.rb', <<-RUBY + get 'win', :to => 'foo#baz' + RUBY + + sleep 0.1 + + get '/win' + + if mode == "development" + assert_equal expected, last_response.body + else + assert_equal 404, last_response.status + end + end + end + {"development" => "baz", "production" => "bar"}.each do |mode, expected| test "reloads routes when configuration is changed in #{mode}" do controller :foo, <<-RUBY |