1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

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.
This commit is contained in:
Andrew White 2013-07-21 17:10:34 +01:00
parent 3613235cc3
commit e5275f9b59
3 changed files with 54 additions and 0 deletions

View file

@ -1,3 +1,11 @@
* 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.
*Andrew White*
* Skip routes pointing to a redirect or mounted application when generating urls
using an options hash as they aren't relevant and generate incorrect urls.

View file

@ -30,6 +30,7 @@ module ActionDispatch
def clear
routes.clear
named_routes.clear
end
def partitioned_routes

View file

@ -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|