mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Ensure routing optimizations are cleared when new routes are added [#981 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
This commit is contained in:
parent
41efd73887
commit
7e6cda15f8
3 changed files with 41 additions and 2 deletions
|
@ -147,6 +147,15 @@ module ActionController
|
||||||
end
|
end
|
||||||
}, __FILE__, __LINE__
|
}, __FILE__, __LINE__
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def clear_recognize_optimized!
|
||||||
|
instance_eval %{
|
||||||
|
def recognize_optimized(path, environment)
|
||||||
|
write_recognize_optimized!
|
||||||
|
recognize_optimized(path, environment)
|
||||||
|
end
|
||||||
|
}, __FILE__, __LINE__
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -195,7 +195,7 @@ module ActionController
|
||||||
self.routes = []
|
self.routes = []
|
||||||
self.named_routes = NamedRouteCollection.new
|
self.named_routes = NamedRouteCollection.new
|
||||||
|
|
||||||
write_recognize_optimized!
|
clear_recognize_optimized!
|
||||||
end
|
end
|
||||||
|
|
||||||
# Subclasses and plugins may override this method to specify a different
|
# Subclasses and plugins may override this method to specify a different
|
||||||
|
@ -217,7 +217,7 @@ module ActionController
|
||||||
@routes_by_controller = nil
|
@routes_by_controller = nil
|
||||||
# This will force routing/recognition_optimization.rb
|
# This will force routing/recognition_optimization.rb
|
||||||
# to refresh optimisations.
|
# to refresh optimisations.
|
||||||
@compiled_recognize_optimized = nil
|
clear_recognize_optimized!
|
||||||
end
|
end
|
||||||
|
|
||||||
def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false)
|
def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false)
|
||||||
|
|
|
@ -1375,6 +1375,36 @@ uses_mocha 'LegacyRouteSet, Route, RouteSet and RouteLoading' do
|
||||||
x.send(:foo_with_requirement_url, "I am Against the requirements")
|
x.send(:foo_with_requirement_url, "I am Against the requirements")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_routes_changed_correctly_after_clear
|
||||||
|
ActionController::Base.optimise_named_routes = true
|
||||||
|
rs = ::ActionController::Routing::RouteSet.new
|
||||||
|
rs.draw do |r|
|
||||||
|
r.connect 'ca', :controller => 'ca', :action => "aa"
|
||||||
|
r.connect 'cb', :controller => 'cb', :action => "ab"
|
||||||
|
r.connect 'cc', :controller => 'cc', :action => "ac"
|
||||||
|
r.connect ':controller/:action/:id'
|
||||||
|
r.connect ':controller/:action/:id.:format'
|
||||||
|
end
|
||||||
|
|
||||||
|
hash = rs.recognize_path "/cc"
|
||||||
|
|
||||||
|
assert_not_nil hash
|
||||||
|
assert_equal %w(cc ac), [hash[:controller], hash[:action]]
|
||||||
|
|
||||||
|
rs.draw do |r|
|
||||||
|
r.connect 'cb', :controller => 'cb', :action => "ab"
|
||||||
|
r.connect 'cc', :controller => 'cc', :action => "ac"
|
||||||
|
r.connect ':controller/:action/:id'
|
||||||
|
r.connect ':controller/:action/:id.:format'
|
||||||
|
end
|
||||||
|
|
||||||
|
hash = rs.recognize_path "/cc"
|
||||||
|
|
||||||
|
assert_not_nil hash
|
||||||
|
assert_equal %w(cc ac), [hash[:controller], hash[:action]]
|
||||||
|
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class RouteTest < Test::Unit::TestCase
|
class RouteTest < Test::Unit::TestCase
|
||||||
|
|
Loading…
Reference in a new issue