Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure routing optimizations are cleared when new routes are added [#981

 state:resolved]

Signed-off-by: Joshua Peek <josh@joshpeek.com>
  • Loading branch information...
commit d4ef5908edfd471dfd3635a7264b5f8aafe246b6 1 parent d4eb3c0
Matt Jones al2o3cr authored josh committed
12 actionpack/lib/action_controller/routing/recognition_optimisation.rb
View
@@ -68,12 +68,16 @@ def recognize_path(path, environment={})
end
end
- def recognize_optimized(path, env)
- write_recognize_optimized
- recognize_optimized(path, env)
+ def clear_recognize_optimized!
+ instance_eval %{
+ def recognize_optimized(path, env)
+ write_recognize_optimized!
+ recognize_optimized(path, env)
+ end
+ }, __FILE__, __LINE__
end
- def write_recognize_optimized
+ def write_recognize_optimized!
tree = segment_tree(routes)
body = generate_code(tree)
instance_eval %{
5 actionpack/lib/action_controller/routing/route_set.rb
View
@@ -194,6 +194,7 @@ def #{selector}(*args)
def initialize
self.routes = []
self.named_routes = NamedRouteCollection.new
+ clear_recognize_optimized!
end
# Subclasses and plugins may override this method to specify a different
@@ -213,9 +214,9 @@ def clear!
named_routes.clear
@combined_regexp = nil
@routes_by_controller = nil
- # This will force routing/recognition_optimization.rb
+ # This will force routing/recognition_optimisation.rb
# to refresh optimisations.
- @compiled_recognize_optimized = nil
+ clear_recognize_optimized!
end
def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false)
29 actionpack/test/controller/routing_test.rb
View
@@ -671,6 +671,35 @@ def test_failed_requirements_raises_exception_with_violated_requirements
x.send(:foo_with_requirement_url, "I am Against the requirements")
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
class SegmentTest < Test::Unit::TestCase
Please sign in to comment.
Something went wrong with that request. Please try again.