diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-14 13:15:57 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-14 13:22:36 +0000 |
commit | 01d3a36bfe5d56d85f8a36f2fe10ad96662b4530 (patch) | |
tree | 217d1c5719c834a30e59975bc1ef53bead2bc9ad /railties/test | |
parent | a16da3f25f068119679792e4c64a7eac7bfe911a (diff) | |
download | rails-01d3a36bfe5d56d85f8a36f2fe10ad96662b4530.tar.gz rails-01d3a36bfe5d56d85f8a36f2fe10ad96662b4530.tar.bz2 rails-01d3a36bfe5d56d85f8a36f2fe10ad96662b4530.zip |
Clear url helper methods when routes are reloaded
Remove all the old url helper methods when clear! is called on the
route set because it's possible that some routes have been removed.
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/routing_test.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 3691ad2723..22de640236 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -277,6 +277,77 @@ module ApplicationTests end end + test 'routes are added and removed when reloading' do + app('development') + + controller :foo, <<-RUBY + class FooController < ApplicationController + def index + render text: "foo" + end + end + RUBY + + controller :bar, <<-RUBY + class BarController < ApplicationController + def index + render text: "bar" + end + end + RUBY + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + get 'foo', to: 'foo#index' + end + RUBY + + get '/foo' + assert_equal 'foo', last_response.body + assert_equal '/foo', Rails.application.routes.url_helpers.foo_path + + get '/bar' + assert_equal 404, last_response.status + assert_raises NoMethodError do + assert_equal '/bar', Rails.application.routes.url_helpers.bar_path + end + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + get 'foo', to: 'foo#index' + get 'bar', to: 'bar#index' + end + RUBY + + Rails.application.reload_routes! + + get '/foo' + assert_equal 'foo', last_response.body + assert_equal '/foo', Rails.application.routes.url_helpers.foo_path + + get '/bar' + assert_equal 'bar', last_response.body + assert_equal '/bar', Rails.application.routes.url_helpers.bar_path + + app_file 'config/routes.rb', <<-RUBY + AppTemplate::Application.routes.draw do + get 'foo', to: 'foo#index' + end + RUBY + + Rails.application.reload_routes! + + get '/foo' + assert_equal 'foo', last_response.body + assert_equal '/foo', Rails.application.routes.url_helpers.foo_path + + get '/bar' + assert_equal 404, last_response.status + assert_raises NoMethodError do + assert_equal '/bar', Rails.application.routes.url_helpers.bar_path + end + end + test 'resource routing with irregular inflection' do app_file 'config/initializers/inflection.rb', <<-RUBY ActiveSupport::Inflector.inflections do |inflect| |