From c2108926a4638b5373f846c2d6165bf28108b9cb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 4 Mar 2015 11:02:24 -0800 Subject: [PATCH] Drop request class from RouteSet constructor. If you would like to use a custom request class, please subclass and implemet the `request_class` method. --- actionpack/CHANGELOG.md | 7 +++++++ actionpack/lib/action_dispatch/routing/route_set.rb | 11 +++++++---- actionpack/test/dispatch/routing_test.rb | 6 +++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 3343a92bf7..108ebfda58 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,10 @@ +* Drop request class from RouteSet constructor. + + If you would like to use a custom request class, please subclass and implemet + the `request_class` method. + + *tenderlove@ruby-lang.org* + * Fallback to `ENV['RAILS_RELATIVE_URL_ROOT']` in `url_for`. Fixed an issue where the `RAILS_RELATIVE_URL_ROOT` environment variable is not diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 29853a3474..6d964c2cbf 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -311,7 +311,7 @@ def define_url_helper(mod, route, name, opts, route_key, url_strategy) attr_accessor :formatter, :set, :named_routes, :default_scope, :router attr_accessor :disable_clear_and_finalize, :resources_path_names - attr_accessor :default_url_options, :request_class + attr_accessor :default_url_options attr_reader :env_key alias :routes :set @@ -320,11 +320,10 @@ def self.default_resources_path_names { :new => 'new', :edit => 'edit' } end - def initialize(request_class = ActionDispatch::Request) + def initialize self.named_routes = NamedRouteCollection.new self.resources_path_names = self.class.default_resources_path_names self.default_url_options = {} - self.request_class = request_class @append = [] @prepend = [] @@ -337,6 +336,10 @@ def initialize(request_class = ActionDispatch::Request) @formatter = Journey::Formatter.new @set end + def request_class + ActionDispatch::Request + end + def draw(&block) clear! unless @disable_clear_and_finalize eval_block(block) @@ -545,7 +548,7 @@ def build_conditions(current_conditions, path_values) conditions.keep_if do |k, _| k == :action || k == :controller || k == :required_defaults || - @request_class.public_method_defined?(k) || path_values.include?(k) + request_class.public_method_defined?(k) || path_values.include?(k) end end private :build_conditions diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index b4502c19d6..55fc160ac8 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -3583,7 +3583,11 @@ def call(env) end end - AltRoutes = ActionDispatch::Routing::RouteSet.new(AltRequest) + AltRoutes = Class.new(ActionDispatch::Routing::RouteSet) { + def request_class + AltRequest + end + }.new AltRoutes.draw do get "/" => TestAltApp::XHeader.new, :constraints => {:x_header => /HEADER/} get "/" => TestAltApp::AltApp.new