Deprecated "best fit" detection is to difficult. Just provide a switch to toggle the new behavor on.

# new_rails_defaults.rb
  ActionController::Routing.generate_best_match = false
This commit is contained in:
Joshua Peek
2009-08-31 16:09:47 -05:00
parent 49c4a79e59
commit 6fdfe4cb5f
4 changed files with 9 additions and 19 deletions

View File

@@ -271,6 +271,9 @@ module ActionController
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 = []

View File

@@ -406,24 +406,11 @@ module ActionController
# 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

View File

@@ -2191,10 +2191,8 @@ class RouteSetTest < ActiveSupport::TestCase
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

View File

@@ -11,6 +11,8 @@ if defined?(ActiveRecord)
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