Permalink
Browse files

Deprecated "best fit" detection is to difficult. Just provide a switc…

…h to toggle the new behavor on.

  # new_rails_defaults.rb
  ActionController::Routing.generate_best_match = false
  • Loading branch information...
1 parent 49c4a79 commit 6fdfe4cb5fa85160f5d91bad64d5c23b4f87f820 @josh josh committed Aug 31, 2009
@@ -271,6 +271,9 @@ module Routing
ALLOWED_REQUIREMENTS_FOR_OPTIMISATION = [:controller, :action].to_set
+ mattr_accessor :generate_best_match
+ self.generate_best_match = true
+
# The root paths which may contain controller files
mattr_accessor :controller_paths
self.controller_paths = []
@@ -406,24 +406,11 @@ def generate(options, recall = {}, method=:generate)
# don't use the recalled keys when determining which routes to check
future_routes, deprecated_routes = routes_by_controller[controller][action][options.reject {|k,v| !v}.keys.sort_by { |x| x.object_id }]
- no_worries = future_routes == deprecated_routes
+ routes = Routing.generate_best_match ? deprecated_routes : future_routes
- deprecated_routes.each_with_index do |route, index|
+ routes.each_with_index do |route, index|
results = route.__send__(method, options, merged, expire_on)
if results && (!results.is_a?(Array) || results.first)
-
- # Compare results with Rails 3.0 behavior
- unless no_worries
- future_routes.each_with_index do |route2, index2|
- new_results = route2.__send__(method, options, merged, expire_on)
- if new_results && (!new_results.is_a?(Array) || new_results.first) && index2 < future_routes.index(route)
- ActiveSupport::Deprecation.warn "The URL you generated will use the first matching route in routes.rb rather than the \"best\" match. " +
- "In Rails 3.0 #{new_results} will be generated instead of #{results}"
- break
- end
- end
- end
-
return results
end
end
@@ -2191,10 +2191,8 @@ def test_generate_finds_best_fit
map.connect "/ws/people", :controller => "people", :action => "index", :ws => true
end
- assert_deprecated {
- url = set.generate(:controller => "people", :action => "index", :ws => true)
- assert_equal "/ws/people", url
- }
+ url = set.generate(:controller => "people", :action => "index", :ws => true)
+ assert_equal "/ws/people", url
end
def test_generate_changes_controller_module
@@ -11,6 +11,8 @@
ActiveRecord::Base.store_full_sti_class = true
end
+ActionController::Routing.generate_best_match = false
+
# Use ISO 8601 format for JSON serialized times and dates.
ActiveSupport.use_standard_json_time_format = true

0 comments on commit 6fdfe4c

Please sign in to comment.