aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/CHANGELOG.md7
-rw-r--r--actionpack/Rakefile5
-rw-r--r--actionpack/lib/action_controller/metal/conditional_get.rb2
-rw-r--r--actionpack/lib/action_controller/metal/http_authentication.rb2
-rw-r--r--actionpack/lib/action_controller/metal/params_wrapper.rb2
-rw-r--r--actionpack/lib/action_controller/metal/url_for.rb5
-rw-r--r--actionpack/lib/action_dispatch/http/filter_redirect.rb2
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb4
-rw-r--r--actionpack/lib/action_dispatch/railtie.rb2
-rw-r--r--actionpack/lib/action_dispatch/routing/route_set.rb31
-rw-r--r--actionpack/lib/action_dispatch/testing/integration.rb15
-rw-r--r--actionpack/lib/action_dispatch/testing/test_response.rb2
-rw-r--r--actionpack/test/abstract_unit.rb5
-rw-r--r--actionpack/test/controller/url_for_test.rb16
-rw-r--r--actionpack/test/dispatch/routing_test.rb6
15 files changed, 66 insertions, 40 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/Rakefile b/actionpack/Rakefile
index 4b60b77759..3bd27f8d64 100644
--- a/actionpack/Rakefile
+++ b/actionpack/Rakefile
@@ -9,10 +9,7 @@ task :default => :test
# Run the unit tests
Rake::TestTask.new do |t|
t.libs << 'test'
-
- # make sure we include the tests in alphabetical order as on some systems
- # this will not happen automatically and the tests (as a whole) will error
- t.test_files = test_files.sort
+ t.test_files = test_files
t.warning = true
t.verbose = true
diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb
index 858870d8b8..47bcfdb1e9 100644
--- a/actionpack/lib/action_controller/metal/conditional_get.rb
+++ b/actionpack/lib/action_controller/metal/conditional_get.rb
@@ -15,7 +15,7 @@ module ActionController
module ClassMethods
# Allows you to consider additional controller-wide information when generating an ETag.
# For example, if you serve pages tailored depending on who's logged in at the moment, you
- # may want to add the current user id to be part of the ETag to prevent authorized displaying
+ # may want to add the current user id to be part of the ETag to prevent unauthorized displaying
# of cached pages.
#
# class InvoicesController < ApplicationController
diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb
index 20afcee537..2273406948 100644
--- a/actionpack/lib/action_controller/metal/http_authentication.rb
+++ b/actionpack/lib/action_controller/metal/http_authentication.rb
@@ -314,7 +314,7 @@ module ActionController
nonce(secret_key, t) == value && (t - Time.now.to_i).abs <= seconds_to_timeout
end
- # Opaque based on random generation - but changing each request?
+ # Opaque based on digest of secret key
def opaque(secret_key)
::Digest::MD5.hexdigest(secret_key)
end
diff --git a/actionpack/lib/action_controller/metal/params_wrapper.rb b/actionpack/lib/action_controller/metal/params_wrapper.rb
index a7e734db42..0a04848eba 100644
--- a/actionpack/lib/action_controller/metal/params_wrapper.rb
+++ b/actionpack/lib/action_controller/metal/params_wrapper.rb
@@ -131,7 +131,7 @@ module ActionController
private
# Determine the wrapper model from the controller's name. By convention,
# this could be done by trying to find the defined model that has the
- # same singularize name as the controller. For example, +UsersController+
+ # same singular name as the controller. For example, +UsersController+
# will try to find if the +User+ model exists.
#
# This method also does namespace lookup. Foo::Bar::UsersController will
diff --git a/actionpack/lib/action_controller/metal/url_for.rb b/actionpack/lib/action_controller/metal/url_for.rb
index 572d1770f7..fbaa90d521 100644
--- a/actionpack/lib/action_controller/metal/url_for.rb
+++ b/actionpack/lib/action_controller/metal/url_for.rb
@@ -4,7 +4,10 @@ module ActionController
#
# In addition to <tt>AbstractController::UrlFor</tt>, this module accesses the HTTP layer to define
# url options like the +host+. In order to do so, this module requires the host class
- # to implement +env+ and +request+, which need to be a Rack-compatible.
+ # to implement +env+ which needs to be Rack-compatible and +request+
+ # which is either instance of +ActionDispatch::Request+ or an object
+ # that responds to <tt>host</tt>, <tt>optional_port</tt>, <tt>protocol</tt> and
+ # <tt>symbolized_path_parameter</tt> methods.
#
# class RootUrl
# include ActionController::UrlFor
diff --git a/actionpack/lib/action_dispatch/http/filter_redirect.rb b/actionpack/lib/action_dispatch/http/filter_redirect.rb
index cd603649c3..bf79963351 100644
--- a/actionpack/lib/action_dispatch/http/filter_redirect.rb
+++ b/actionpack/lib/action_dispatch/http/filter_redirect.rb
@@ -4,7 +4,7 @@ module ActionDispatch
FILTERED = '[FILTERED]'.freeze # :nodoc:
- def filtered_location
+ def filtered_location # :nodoc:
filters = location_filter
if !filters.empty? && location_filter_match?(filters)
FILTERED
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 5fe544c60c..a895d1ab18 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -113,9 +113,7 @@ module ActionDispatch # :nodoc:
# The underlying body, as a streamable object.
attr_reader :stream
- # Ruby 2.2 bug https://bugs.ruby-lang.org/issues/10685 prevents
- # default_headers from being a keyword argument.
- def initialize(status = 200, header = {}, body = [], default_headers = self.class.default_headers)
+ def initialize(status = 200, header = {}, body = [], default_headers: self.class.default_headers)
super()
header = merge_default_headers(header, default_headers)
diff --git a/actionpack/lib/action_dispatch/railtie.rb b/actionpack/lib/action_dispatch/railtie.rb
index 8cde5eb6f7..ddeea24bb3 100644
--- a/actionpack/lib/action_dispatch/railtie.rb
+++ b/actionpack/lib/action_dispatch/railtie.rb
@@ -40,8 +40,6 @@ module ActionDispatch
ActionDispatch::Cookies::CookieJar.always_write_cookie = config.action_dispatch.always_write_cookie
ActionDispatch.test_app = app
-
- ActionDispatch::Routing::RouteSet.relative_url_root = app.config.relative_url_root
end
end
end
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb
index 29853a3474..0f3734dd74 100644
--- a/actionpack/lib/action_dispatch/routing/route_set.rb
+++ b/actionpack/lib/action_dispatch/routing/route_set.rb
@@ -20,8 +20,6 @@ module ActionDispatch
# alias inspect to to_s.
alias inspect to_s
- mattr_accessor :relative_url_root
-
class Dispatcher < Routing::Endpoint
def initialize(defaults)
@defaults = defaults
@@ -311,7 +309,7 @@ module ActionDispatch
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,12 +318,25 @@ module ActionDispatch
{ :new => 'new', :edit => 'edit' }
end
- def initialize(request_class = ActionDispatch::Request)
+ def self.new_with_config(config)
+ if config.respond_to? :relative_url_root
+ new Config.new config.relative_url_root
+ else
+ # engines apparently don't have this set
+ new
+ end
+ end
+
+ Config = Struct.new :relative_url_root
+
+ DEFAULT_CONFIG = Config.new(nil)
+
+ def initialize(config = DEFAULT_CONFIG)
self.named_routes = NamedRouteCollection.new
self.resources_path_names = self.class.default_resources_path_names
self.default_url_options = {}
- self.request_class = request_class
+ @config = config
@append = []
@prepend = []
@disable_clear_and_finalize = false
@@ -337,6 +348,14 @@ module ActionDispatch
@formatter = Journey::Formatter.new @set
end
+ def relative_url_root
+ @config.relative_url_root
+ end
+
+ def request_class
+ ActionDispatch::Request
+ end
+
def draw(&block)
clear! unless @disable_clear_and_finalize
eval_block(block)
@@ -545,7 +564,7 @@ module ActionDispatch
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/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb
index f7f898288b..61e7d9fcc5 100644
--- a/actionpack/lib/action_dispatch/testing/integration.rb
+++ b/actionpack/lib/action_dispatch/testing/integration.rb
@@ -508,8 +508,8 @@ module ActionDispatch
# assert_equal 200, status
#
# # post the login and follow through to the home page
- # post "/login", username: people(:jamis).username,
- # password: people(:jamis).password
+ # post "/login", params: { username: people(:jamis).username,
+ # password: people(:jamis).password }
# follow_redirect!
# assert_equal 200, status
# assert_equal "/home", path
@@ -548,7 +548,7 @@ module ActionDispatch
# end
#
# def speak(room, message)
- # xml_http_request "/say/#{room.id}", message: message
+ # post "/say/#{room.id}", xhr: true, params: { message: message }
# assert(...)
# ...
# end
@@ -558,8 +558,8 @@ module ActionDispatch
# open_session do |sess|
# sess.extend(CustomAssertions)
# who = people(who)
- # sess.post "/login", username: who.username,
- # password: who.password
+ # sess.post "/login", params: { username: who.username,
+ # password: who.password }
# assert(...)
# end
# end
@@ -578,7 +578,8 @@ module ActionDispatch
# get "/login"
# assert_response :success
#
- # post_via_redirect "/login", username: users(:david).username, password: users(:david).password
+ # post "/login", params: { username: users(:david).username, password: users(:david).password }
+ # follow_redirect!
# assert_equal '/welcome', path
# assert_equal 'Welcome david!', flash[:notice]
#
@@ -633,7 +634,7 @@ module ActionDispatch
# sess.extend(CustomDsl)
# u = users(user)
# sess.https!
- # sess.post "/login", username: u.username, password: u.password
+ # sess.post "/login", params: { username: u.username, password: u.password }
# assert_equal '/welcome', sess.path
# sess.https!(false)
# end
diff --git a/actionpack/lib/action_dispatch/testing/test_response.rb b/actionpack/lib/action_dispatch/testing/test_response.rb
index 527784885c..a9b88ac5fd 100644
--- a/actionpack/lib/action_dispatch/testing/test_response.rb
+++ b/actionpack/lib/action_dispatch/testing/test_response.rb
@@ -7,7 +7,7 @@ module ActionDispatch
# See Response for more information on controller response objects.
class TestResponse < Response
def self.from_response(response)
- new response.status, response.headers, response.body, nil
+ new response.status, response.headers, response.body, default_headers: nil
end
# Was the response successful?
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb
index f5dd9d76af..62ff1be5c9 100644
--- a/actionpack/test/abstract_unit.rb
+++ b/actionpack/test/abstract_unit.rb
@@ -483,8 +483,3 @@ if RUBY_ENGINE == "ruby" && PROCESS_COUNT > 0
# Use N processes (N defaults to 4)
Minitest.parallel_executor = ForkingExecutor.new(PROCESS_COUNT)
end
-
-# FIXME: we have tests that depend on run order, we should fix that and
-# remove this method call.
-require 'active_support/test_case'
-ActiveSupport::TestCase.test_order = :sorted
diff --git a/actionpack/test/controller/url_for_test.rb b/actionpack/test/controller/url_for_test.rb
index cd63493b32..31677f202d 100644
--- a/actionpack/test/controller/url_for_test.rb
+++ b/actionpack/test/controller/url_for_test.rb
@@ -30,8 +30,8 @@ module AbstractController
assert_equal '/foo/zot', path
end
- def add_host!
- W.default_url_options[:host] = 'www.basecamphq.com'
+ def add_host!(app = W)
+ app.default_url_options[:host] = 'www.basecamphq.com'
end
def add_port!
@@ -257,12 +257,16 @@ module AbstractController
def test_relative_url_root_is_respected_with_environment_variable
# `config.relative_url_root` is set by ENV['RAILS_RELATIVE_URL_ROOT']
- ActionDispatch::Routing::RouteSet.relative_url_root = '/subdir'
- add_host!
+ w = Class.new {
+ config = ActionDispatch::Routing::RouteSet::Config.new '/subdir'
+ r = ActionDispatch::Routing::RouteSet.new(config)
+ r.draw { get ':controller(/:action(/:id(.:format)))' }
+ include r.url_helpers
+ }
+ add_host!(w)
assert_equal('https://www.basecamphq.com/subdir/c/a/i',
- W.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
+ w.new.url_for(:controller => 'c', :action => 'a', :id => 'i', :protocol => 'https')
)
- ActionDispatch::Routing::RouteSet.relative_url_root = nil
end
def test_named_routes
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 @@ class TestAltApp < ActionDispatch::IntegrationTest
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