diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-21 17:10:34 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-07-21 17:11:52 +0100 |
commit | e5275f9b5924f36f2bdd4dd9ac0a4f420384748f (patch) | |
tree | fac9d13131a8892725a1a4d50b2087daf8dc9a52 /railties/test | |
parent | 3613235cc3d7d87ce02e51a80f67706c0853b524 (diff) | |
download | rails-e5275f9b5924f36f2bdd4dd9ac0a4f420384748f.tar.gz rails-e5275f9b5924f36f2bdd4dd9ac0a4f420384748f.tar.bz2 rails-e5275f9b5924f36f2bdd4dd9ac0a4f420384748f.zip |
Clear named routes when routes.rb is reloaded
Fix an issue where Journey was failing to clear the named routes hash when the
routes were reloaded and since it doesn't overwrite existing routes then if a
route changed but wasn't renamed it kept the old definition. This was being
masked by the optimised url helpers so it only became apparent when passing an
options hash to the url helper.
Diffstat (limited to 'railties/test')
-rw-r--r-- | railties/test/application/routing_test.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/railties/test/application/routing_test.rb b/railties/test/application/routing_test.rb index 1a4e2d4123..8576a2b738 100644 --- a/railties/test/application/routing_test.rb +++ b/railties/test/application/routing_test.rb @@ -372,6 +372,51 @@ module ApplicationTests end end + test 'named routes are cleared 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 + Rails.application.routes.draw do + get ':locale/foo', to: 'foo#index', as: 'foo' + end + RUBY + + get '/en/foo' + assert_equal 'foo', last_response.body + assert_equal '/en/foo', Rails.application.routes.url_helpers.foo_path(:locale => 'en') + + app_file 'config/routes.rb', <<-RUBY + Rails.application.routes.draw do + get ':locale/bar', to: 'bar#index', as: 'foo' + end + RUBY + + Rails.application.reload_routes! + + get '/en/foo' + assert_equal 404, last_response.status + + get '/en/bar' + assert_equal 'bar', last_response.body + assert_equal '/en/bar', Rails.application.routes.url_helpers.foo_path(:locale => 'en') + end + test 'resource routing with irregular inflection' do app_file 'config/initializers/inflection.rb', <<-RUBY ActiveSupport::Inflector.inflections do |inflect| |