From 363a06f351e2d52d3717ea3334c174665ac72103 Mon Sep 17 00:00:00 2001 From: Yehuda Katz Date: Wed, 25 Apr 2012 22:45:56 -0500 Subject: Routes reloader knows how to reload external files --- railties/test/application/routing_test.rb | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'railties/test/application') diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 1dac086119..4560dcec69 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -190,6 +190,67 @@ module ApplicationTests 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 -- cgit v1.2.3