diff options
Diffstat (limited to 'actionpack')
47 files changed, 279 insertions, 1356 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index 96af4d9397..3effa89f07 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,132 @@ +* Remove deprecated support to non-keyword arguments in `ActionDispatch::IntegrationTest#process`, + `#get`, `#post`, `#patch`, `#put`, `#delete`, and `#head`. + + *Rafael Mendonça França* + +* Remove deprecated `ActionDispatch::IntegrationTest#*_via_redirect`. + + *Rafael Mendonça França* + +* Remove deprecated `ActionDispatch::IntegrationTest#xml_http_request`. + + *Rafael Mendonça França* + +* Remove deprecated support for passing `:path` and route path as stings in `ActionDispatch::Routing::Mapper#match`. + + *Rafael Mendonça França* + +* Remove deprecated support for passing path as `nil` in `ActionDispatch::Routing::Mapper#match`. + + *Rafael Mendonça França* + +* Remove deprecated `cache_control` argument from `ActionDispatch::Static#initialize`. + + *Rafael Mendonça França* + +* Remove deprecated support to passing strings or symbols to the middleware stack. + + *Rafael Mendonça França* + +* Change HSTS subdomain to true. + + *Rafael Mendonça França* + +* Remove deprecated `host` and `port` ssl options. + + *Rafael Mendonça França* + +* Remove deprecated `const_error` argument in + `ActionDispatch::Session::SessionRestoreError#initialize`. + + *Rafael Mendonça França* + +* Remove deprecated `#original_exception` in `ActionDispatch::Session::SessionRestoreError`. + + *Rafael Mendonça França* + +* Deprecate `ActionDispatch::ParamsParser::ParseError` in favor of + `ActionDispatch::Http::Parameters::ParseError`. + + *Rafael Mendonça França* + +* Remove deprecated `ActionDispatch::ParamsParser`. + + *Rafael Mendonça França* + +* Remove deprecated `original_exception` and `message` arguments in + `ActionDispatch::ParamsParser::ParseError#initialize`. + + *Rafael Mendonça França* + +* Remove deprecated `#original_exception` in `ActionDispatch::ParamsParser::ParseError`. + + *Rafael Mendonça França* + +* Remove deprecated access to mime types through constants. + + *Rafael Mendonça França* + +* Remove deprecated support to non-keyword arguments in `ActionController::TestCase#process`, + `#get`, `#post`, `#patch`, `#put`, `#delete`, and `#head`. + + *Rafael Mendonça França* + +* Remove deprecated `xml_http_request` and `xhr` methods in `ActionController::TestCase`. + + *Rafael Mendonça França* + +* Remove deprecated methods in `ActionController::Parameters`. + + *Rafael Mendonça França* + +* Remove deprecated support to comparing a `ActionController::Parameters` + with a `Hash`. + + *Rafael Mendonça França* + +* Remove deprecated support to `:text` in `render`. + + *Rafael Mendonça França* + +* Remove deprecated support to `:nothing` in `render`. + + *Rafael Mendonça França* + +* Remove deprecated support to `:back` in `redirect_to`. + + *Rafael Mendonça França* + +* Remove deprecated support to passing status as option `head`. + + *Rafael Mendonça França* + +* Remove deprecated support to passing original exception to `ActionController::BadRequest` + and the `ActionController::BadRequest#original_exception` method. + + *Rafael Mendonça França* + +* Remove deprecated methods `skip_action_callback`, `skip_filter`, `before_filter`, + `prepend_before_filter`, `skip_before_filter`, `append_before_filter`, `around_filter` + `prepend_around_filter`, `skip_around_filter`, `append_around_filter`, `after_filter`, + `prepend_after_filter`, `skip_after_filter` and `append_after_filter`. + + *Rafael Mendonça França* + +* Show an "unmatched constraints" error when params fail to match constraints + on a matched route, rather than a "missing keys" error. + + Fixes #26470. + + *Chris Carter* + +* Fix adding implicitly rendered template digests to ETags. + + Fixes a case when modifying an implicitly rendered template for a + controller action using `fresh_when` or `stale?` would not result in a new + `ETag` value. + + *Javan Makhmali* + * Make `fixture_file_upload` work in integration tests. *Yuji Yaginuma* diff --git a/actionpack/lib/abstract_controller/callbacks.rb b/actionpack/lib/abstract_controller/callbacks.rb index 73775e12c2..ce4ecf17cc 100644 --- a/actionpack/lib/abstract_controller/callbacks.rb +++ b/actionpack/lib/abstract_controller/callbacks.rb @@ -54,25 +54,6 @@ module AbstractController end end - # Skip before, after, and around action callbacks matching any of the names. - # - # ==== Parameters - # * <tt>names</tt> - A list of valid names that could be used for - # callbacks. Note that skipping uses Ruby equality, so it's - # impossible to skip a callback defined using an anonymous proc - # using #skip_action_callback. - def skip_action_callback(*names) - ActiveSupport::Deprecation.warn("`skip_action_callback` is deprecated and will be removed in Rails 5.1. Please use skip_before_action, skip_after_action or skip_around_action instead.") - skip_before_action(*names, raise: false) - skip_after_action(*names, raise: false) - skip_around_action(*names, raise: false) - end - - def skip_filter(*names) - ActiveSupport::Deprecation.warn("`skip_filter` is deprecated and will be removed in Rails 5.1. Use skip_before_action, skip_after_action or skip_around_action instead.") - skip_action_callback(*names) - end - # Take callback names and an optional callback proc, normalize them, # then call the block with each callback. This allows us to abstract # the normalization across several methods that use it. @@ -187,22 +168,12 @@ module AbstractController end end - define_method "#{callback}_filter" do |*names, &blk| - ActiveSupport::Deprecation.warn("#{callback}_filter is deprecated and will be removed in Rails 5.1. Use #{callback}_action instead.") - send("#{callback}_action", *names, &blk) - end - define_method "prepend_#{callback}_action" do |*names, &blk| _insert_callbacks(names, blk) do |name, options| set_callback(:process_action, callback, name, options.merge(prepend: true)) end end - define_method "prepend_#{callback}_filter" do |*names, &blk| - ActiveSupport::Deprecation.warn("prepend_#{callback}_filter is deprecated and will be removed in Rails 5.1. Use prepend_#{callback}_action instead.") - send("prepend_#{callback}_action", *names, &blk) - end - # Skip a before, after or around callback. See _insert_callbacks # for details on the allowed parameters. define_method "skip_#{callback}_action" do |*names| @@ -211,18 +182,8 @@ module AbstractController end end - define_method "skip_#{callback}_filter" do |*names, &blk| - ActiveSupport::Deprecation.warn("skip_#{callback}_filter is deprecated and will be removed in Rails 5.1. Use skip_#{callback}_action instead.") - send("skip_#{callback}_action", *names, &blk) - end - # *_action is the same as append_*_action alias_method :"append_#{callback}_action", :"#{callback}_action" - - define_method "append_#{callback}_filter" do |*names, &blk| - ActiveSupport::Deprecation.warn("append_#{callback}_filter is deprecated and will be removed in Rails 5.1. Use append_#{callback}_action instead.") - send("append_#{callback}_action", *names, &blk) - end end end end diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 075e4504c2..ed93a2f09c 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -55,7 +55,7 @@ module ActionController list = except end - Middleware.new(get_class(klass), args, list, strategy, block) + Middleware.new(klass, args, list, strategy, block) end end diff --git a/actionpack/lib/action_controller/metal/exceptions.rb b/actionpack/lib/action_controller/metal/exceptions.rb index 56a4b085e2..3761e6172b 100644 --- a/actionpack/lib/action_controller/metal/exceptions.rb +++ b/actionpack/lib/action_controller/metal/exceptions.rb @@ -3,20 +3,10 @@ module ActionController end class BadRequest < ActionControllerError #:nodoc: - def initialize(msg = nil, e = nil) - if e - ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \ - "Exceptions will automatically capture the original exception.", caller) - end - + def initialize(msg = nil) super(msg) set_backtrace $!.backtrace if $! end - - def original_exception - ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller) - cause - end end class RenderError < ActionControllerError #:nodoc: diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb index 86b5eb20d7..4dff23dd85 100644 --- a/actionpack/lib/action_controller/metal/head.rb +++ b/actionpack/lib/action_controller/metal/head.rb @@ -18,13 +18,7 @@ module ActionController # See Rack::Utils::SYMBOL_TO_STATUS_CODE for a full list of valid +status+ symbols. def head(status, options = {}) if status.is_a?(Hash) - msg = status[:status] ? "The :status option" : "The implicit :ok status" - options, status = status, status.delete(:status) - - ActiveSupport::Deprecation.warn(<<-MSG.squish) - #{msg} on `head` has been deprecated and will be removed in Rails 5.1. - Please pass the status as a separate parameter before the options, instead. - MSG + raise ArgumentError, "#{status.inspect} is not a valid value for `status`." end status ||= :ok diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index 2bd4296aff..2b060e3698 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -24,10 +24,10 @@ module ActionController # === Examples: # # redirect_to action: "show", id: 5 - # redirect_to post + # redirect_to @post # redirect_to "http://www.rubyonrails.org" # redirect_to "/images/screenshot.jpg" - # redirect_to articles_url + # redirect_to posts_url # redirect_to proc { edit_post_url(@post) } # # The redirection happens as a "302 Found" header unless otherwise specified using the <tt>:status</tt> option: @@ -77,11 +77,11 @@ module ActionController # is missing this header, the <tt>fallback_location</tt> will be used. # # redirect_back fallback_location: { action: "show", id: 5 } - # redirect_back fallback_location: post + # redirect_back fallback_location: @post # redirect_back fallback_location: "http://www.rubyonrails.org" - # redirect_back fallback_location: "/images/screenshot.jpg" - # redirect_back fallback_location: articles_url - # redirect_back fallback_location: proc { edit_post_url(@post) } + # redirect_back fallback_location: "/images/screenshot.jpg" + # redirect_back fallback_location: posts_url + # redirect_back fallback_location: proc { edit_post_url(@post) } # # All options that can be passed to <tt>redirect_to</tt> are accepted as # options and the behavior is identical. @@ -104,14 +104,6 @@ module ActionController options when String request.protocol + request.host_with_port + options - when :back - ActiveSupport::Deprecation.warn(<<-MESSAGE.squish) - `redirect_to :back` is deprecated and will be removed from Rails 5.1. - Please use `redirect_back(fallback_location: fallback_location)` where - `fallback_location` represents the location to use if the request has - no HTTP referer information. - MESSAGE - request.headers["Referer"] || raise(RedirectBackError) when Proc _compute_redirect_to_location request, options.call else diff --git a/actionpack/lib/action_controller/metal/renderers.rb b/actionpack/lib/action_controller/metal/renderers.rb index 15377ddcb9..f8a037189c 100644 --- a/actionpack/lib/action_controller/metal/renderers.rb +++ b/actionpack/lib/action_controller/metal/renderers.rb @@ -71,8 +71,6 @@ module ActionController # format.csv { render csv: @csvable, filename: @csvable.name } # end # end - # To use renderers and their mime types in more concise ways, see - # <tt>ActionController::MimeResponds::ClassMethods.respond_to</tt> def self.add(key, &block) define_method(_render_with_renderer_method_name(key), &block) RENDERERS << key.to_sym diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb index f8f91ed41c..67365a143e 100644 --- a/actionpack/lib/action_controller/metal/rendering.rb +++ b/actionpack/lib/action_controller/metal/rendering.rb @@ -4,7 +4,7 @@ module ActionController module Rendering extend ActiveSupport::Concern - RENDER_FORMATS_IN_PRIORITY = [:body, :text, :plain, :html] + RENDER_FORMATS_IN_PRIORITY = [:body, :plain, :html] module ClassMethods # Documentation at ActionController::Renderer#render @@ -83,26 +83,10 @@ module ActionController def _normalize_options(options) #:nodoc: _normalize_text(options) - if options[:text] - ActiveSupport::Deprecation.warn <<-WARNING.squish - `render :text` is deprecated because it does not actually render a - `text/plain` response. Switch to `render plain: 'plain text'` to - render as `text/plain`, `render html: '<strong>HTML</strong>'` to - render as `text/html`, or `render body: 'raw'` to match the deprecated - behavior and render with the default Content-Type, which is - `text/html`. - WARNING - end - if options[:html] options[:html] = ERB::Util.html_escape(options[:html]) end - if options.delete(:nothing) - ActiveSupport::Deprecation.warn("`:nothing` option is deprecated and will be removed in Rails 5.1. Use `head` method to respond with empty response body.") - options[:body] = nil - end - if options[:status] options[:status] = Rack::Utils.status_code(options[:status]) end diff --git a/actionpack/lib/action_controller/metal/strong_parameters.rb b/actionpack/lib/action_controller/metal/strong_parameters.rb index 387c2aa0b9..4db30e64b4 100644 --- a/actionpack/lib/action_controller/metal/strong_parameters.rb +++ b/actionpack/lib/action_controller/metal/strong_parameters.rb @@ -151,15 +151,6 @@ module ActionController def ==(other) if other.respond_to?(:permitted?) self.permitted? == other.permitted? && self.parameters == other.parameters - elsif other.is_a?(Hash) - ActiveSupport::Deprecation.warn <<-WARNING.squish - Comparing equality between `ActionController::Parameters` and a - `Hash` is deprecated and will be removed in Rails 5.1. Please only do - comparisons between instances of `ActionController::Parameters`. If - you need to compare to a hash, first convert it using - `ActionController::Parameters#new`. - WARNING - @parameters == other.with_indifferent_access else @parameters == other end @@ -620,28 +611,8 @@ module ActionController end end - # Undefine `to_param` such that it gets caught in the `method_missing` - # deprecation cycle below. undef_method :to_param - def method_missing(method_sym, *args, &block) - if @parameters.respond_to?(method_sym) - message = <<-DEPRECATE.squish - Method #{method_sym} is deprecated and will be removed in Rails 5.1, - as `ActionController::Parameters` no longer inherits from - hash. Using this deprecated behavior exposes potential security - problems. If you continue to use this method you may be creating - a security vulnerability in your app that can be exploited. Instead, - consider using one of these documented methods which are not - deprecated: http://api.rubyonrails.org/v#{ActionPack.version}/classes/ActionController/Parameters.html - DEPRECATE - ActiveSupport::Deprecation.warn(message) - @parameters.public_send(method_sym, *args, &block) - else - super - end - end - protected attr_reader :parameters diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 09f2a79d85..33c0201951 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -386,57 +386,42 @@ module ActionController # # Note that the request method is not verified. The different methods are # available to make the tests more expressive. - def get(action, *args) - res = process_with_kwargs("GET", action, *args) + def get(action, **args) + res = process(action, method: "GET", **args) cookies.update res.cookies res end # Simulate a POST request with the given parameters and set/volley the response. # See +get+ for more details. - def post(action, *args) - process_with_kwargs("POST", action, *args) + def post(action, **args) + process(action, method: "POST", **args) end # Simulate a PATCH request with the given parameters and set/volley the response. # See +get+ for more details. - def patch(action, *args) - process_with_kwargs("PATCH", action, *args) + def patch(action, **args) + process(action, method: "PATCH", **args) end # Simulate a PUT request with the given parameters and set/volley the response. # See +get+ for more details. - def put(action, *args) - process_with_kwargs("PUT", action, *args) + def put(action, **args) + process(action, method: "PUT", **args) end # Simulate a DELETE request with the given parameters and set/volley the response. # See +get+ for more details. - def delete(action, *args) - process_with_kwargs("DELETE", action, *args) + def delete(action, **args) + process(action, method: "DELETE", **args) end # Simulate a HEAD request with the given parameters and set/volley the response. # See +get+ for more details. - def head(action, *args) - process_with_kwargs("HEAD", action, *args) + def head(action, **args) + process(action, method: "HEAD", **args) end - def xml_http_request(*args) - ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc) - xhr and xml_http_request methods are deprecated in favor of - `get :index, xhr: true` and `post :create, xhr: true` - MSG - - @request.env["HTTP_X_REQUESTED_WITH"] = "XMLHttpRequest" - @request.env["HTTP_ACCEPT"] ||= [Mime[:js], Mime[:html], Mime[:xml], "text/xml", "*/*"].join(", ") - __send__(*args).tap do - @request.env.delete "HTTP_X_REQUESTED_WITH" - @request.env.delete "HTTP_ACCEPT" - end - end - alias xhr :xml_http_request - # Simulate an HTTP request to +action+ by specifying request method, # parameters and set/volley the response. # @@ -467,40 +452,14 @@ module ActionController # respectively which will make tests more expressive. # # Note that the request method is not verified. - def process(action, *args) + def process(action, method: "GET", params: {}, session: nil, body: nil, flash: {}, format: nil, xhr: false, as: nil) check_required_ivars - if kwarg_request?(args) - parameters, session, body, flash, http_method, format, xhr, as = args[0].values_at(:params, :session, :body, :flash, :method, :format, :xhr, :as) - else - http_method, parameters, session, flash = args - format = nil - - if parameters.is_a?(String) && http_method != "HEAD" - body = parameters - parameters = nil - end - - if parameters || session || flash - non_kwarg_request_warning - end - end - if body @request.set_header "RAW_POST_DATA", body end - if http_method - http_method = http_method.to_s.upcase - else - http_method = "GET" - end - - parameters ||= {} - - if format - parameters[:format] = format - end + http_method = method.to_s.upcase @html_document = nil @@ -521,7 +480,11 @@ module ActionController format ||= as end - parameters = parameters.symbolize_keys + parameters = params.symbolize_keys + + if format + parameters[:format] = format + end generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action.to_s)) generated_path = generated_path(generated_extras) @@ -641,38 +604,6 @@ module ActionController env end - def process_with_kwargs(http_method, action, *args) - if kwarg_request?(args) - args.first.merge!(method: http_method) - process(action, *args) - else - non_kwarg_request_warning if args.any? - - args = args.unshift(http_method) - process(action, *args) - end - end - - REQUEST_KWARGS = %i(params session flash method body xhr) - def kwarg_request?(args) - args[0].respond_to?(:keys) && ( - (args[0].key?(:format) && args[0].keys.size == 1) || - args[0].keys.any? { |k| REQUEST_KWARGS.include?(k) } - ) - end - - def non_kwarg_request_warning - ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc) - ActionController::TestCase HTTP request methods will accept only - keyword arguments in future Rails versions. - - Examples: - - get :show, params: { id: 1 }, session: { user_id: 1 } - process :update, method: :post, params: { id: 1 } - MSG - end - def document_root_element html_document.root end diff --git a/actionpack/lib/action_dispatch.rb b/actionpack/lib/action_dispatch.rb index 60cee6acbd..7931e53c3e 100644 --- a/actionpack/lib/action_dispatch.rb +++ b/actionpack/lib/action_dispatch.rb @@ -54,7 +54,6 @@ module ActionDispatch autoload :ExceptionWrapper autoload :Executor autoload :Flash - autoload :ParamsParser autoload :PublicExceptions autoload :Reloader autoload :RemoteIp diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index b9121a577c..58eb8d0baf 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -45,32 +45,6 @@ module Mime return type if type.is_a?(Type) EXTENSION_LOOKUP.fetch(type.to_s) { |k| yield k } end - - def const_missing(sym) - ext = sym.downcase - if Mime[ext] - ActiveSupport::Deprecation.warn(<<-MSG.squish) - Accessing mime types via constants is deprecated. - Please change `Mime::#{sym}` to `Mime[:#{ext}]`. - MSG - Mime[ext] - else - super - end - end - - def const_defined?(sym, inherit = true) - ext = sym.downcase - if Mime[ext] - ActiveSupport::Deprecation.warn(<<-MSG.squish) - Accessing mime types via constants is deprecated. - Please change `Mime.const_defined?(#{sym})` to `Mime[:#{ext}]`. - MSG - true - else - super - end - end end # Encapsulates the notion of a mime type. Can be used at render time, for example, with: diff --git a/actionpack/lib/action_dispatch/http/parameters.rb b/actionpack/lib/action_dispatch/http/parameters.rb index 31ef0af791..ddd15b748b 100644 --- a/actionpack/lib/action_dispatch/http/parameters.rb +++ b/actionpack/lib/action_dispatch/http/parameters.rb @@ -12,6 +12,14 @@ module ActionDispatch } } + # Raised when raw data from the request cannot be parsed by the parser + # defined for request's content mime type. + class ParseError < StandardError + def initialize + super($!.message) + end + end + included do class << self attr_reader :parameter_parsers @@ -91,7 +99,7 @@ module ActionDispatch my_logger = logger || ActiveSupport::Logger.new($stderr) my_logger.debug "Error occurred while parsing request parameters.\nContents:\n\n#{raw_post}" - raise ParamsParser::ParseError + raise ParseError end end @@ -100,4 +108,8 @@ module ActionDispatch end end end + + module ParamsParser + ParseError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("ActionDispatch::ParamsParser::ParseError", "ActionDispatch::Http::Parameters::ParseError") + end end diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index e4ef9783f3..9986d6e1e9 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -357,7 +357,7 @@ module ActionDispatch end self.request_parameters = Request::Utils.normalize_encode_params(pr) end - rescue ParamsParser::ParseError # one of the parse strategies blew up + rescue Http::Parameters::ParseError # one of the parse strategies blew up self.request_parameters = Request::Utils.normalize_encode_params(super || {}) raise rescue Rack::Utils::ParameterTypeError, Rack::Utils::InvalidParameterError => e diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index a289c34e8b..dc8b24b089 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -44,8 +44,12 @@ module ActionDispatch return [route.format(parameterized_parts), params] end + unmatched_keys = (missing_keys || []) & constraints.keys + missing_keys = (missing_keys || []) - unmatched_keys + message = "No route matches #{Hash[constraints.sort_by { |k,v| k.to_s }].inspect}" - message << " missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty? + message << ", missing required keys: #{missing_keys.sort.inspect}" if missing_keys && !missing_keys.empty? + message << ", possible unmatched constraints: #{unmatched_keys.sort.inspect}" if unmatched_keys && !unmatched_keys.empty? raise ActionController::UrlGenerationError, message end diff --git a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb index 9b44c4483e..99dc37c568 100644 --- a/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb +++ b/actionpack/lib/action_dispatch/middleware/exception_wrapper.rb @@ -6,19 +6,19 @@ module ActionDispatch cattr_accessor :rescue_responses @@rescue_responses = Hash.new(:internal_server_error) @@rescue_responses.merge!( - "ActionController::RoutingError" => :not_found, - "AbstractController::ActionNotFound" => :not_found, - "ActionController::MethodNotAllowed" => :method_not_allowed, - "ActionController::UnknownHttpMethod" => :method_not_allowed, - "ActionController::NotImplemented" => :not_implemented, - "ActionController::UnknownFormat" => :not_acceptable, - "ActionController::InvalidAuthenticityToken" => :unprocessable_entity, - "ActionController::InvalidCrossOriginRequest" => :unprocessable_entity, - "ActionDispatch::ParamsParser::ParseError" => :bad_request, - "ActionController::BadRequest" => :bad_request, - "ActionController::ParameterMissing" => :bad_request, - "Rack::QueryParser::ParameterTypeError" => :bad_request, - "Rack::QueryParser::InvalidParameterError" => :bad_request + "ActionController::RoutingError" => :not_found, + "AbstractController::ActionNotFound" => :not_found, + "ActionController::MethodNotAllowed" => :method_not_allowed, + "ActionController::UnknownHttpMethod" => :method_not_allowed, + "ActionController::NotImplemented" => :not_implemented, + "ActionController::UnknownFormat" => :not_acceptable, + "ActionController::InvalidAuthenticityToken" => :unprocessable_entity, + "ActionController::InvalidCrossOriginRequest" => :unprocessable_entity, + "ActionDispatch::Http::Parameters::ParseError" => :bad_request, + "ActionController::BadRequest" => :bad_request, + "ActionController::ParameterMissing" => :bad_request, + "Rack::QueryParser::ParameterTypeError" => :bad_request, + "Rack::QueryParser::InvalidParameterError" => :bad_request ) cattr_accessor :rescue_templates diff --git a/actionpack/lib/action_dispatch/middleware/params_parser.rb b/actionpack/lib/action_dispatch/middleware/params_parser.rb deleted file mode 100644 index 5f96b80e87..0000000000 --- a/actionpack/lib/action_dispatch/middleware/params_parser.rb +++ /dev/null @@ -1,45 +0,0 @@ -require "action_dispatch/http/request" - -module ActionDispatch - # ActionDispatch::ParamsParser works for all the requests having any Content-Length - # (like POST). It takes raw data from the request and puts it through the parser - # that is picked based on Content-Type header. - # - # In case of any error while parsing data ParamsParser::ParseError is raised. - class ParamsParser - # Raised when raw data from the request cannot be parsed by the parser - # defined for request's content mime type. - class ParseError < StandardError - def initialize(message = nil, original_exception = nil) - if message - ActiveSupport::Deprecation.warn("Passing #message is deprecated and has no effect. " \ - "#{self.class} will automatically capture the message " \ - "of the original exception.", caller) - end - - if original_exception - ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \ - "Exceptions will automatically capture the original exception.", caller) - end - - super($!.message) - end - - def original_exception - ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller) - cause - end - end - - # Create a new +ParamsParser+ middleware instance. - # - # The +parsers+ argument can take Hash of parsers where key is identifying - # content mime type, and value is a lambda that is going to process data. - def self.new(app, parsers = {}) - ActiveSupport::Deprecation.warn("ActionDispatch::ParamsParser is deprecated and will be removed in Rails 5.1. Configure the parameter parsing in ActionDispatch::Request.parameter_parsers.") - parsers = parsers.transform_keys { |key| key.respond_to?(:symbol) ? key.symbol : key } - ActionDispatch::Request.parameter_parsers = ActionDispatch::Request::DEFAULT_PARSERS.merge(parsers) - app - end - end -end diff --git a/actionpack/lib/action_dispatch/middleware/request_id.rb b/actionpack/lib/action_dispatch/middleware/request_id.rb index bd4c781267..1925ffd9dd 100644 --- a/actionpack/lib/action_dispatch/middleware/request_id.rb +++ b/actionpack/lib/action_dispatch/middleware/request_id.rb @@ -2,8 +2,9 @@ require "securerandom" require "active_support/core_ext/string/access" module ActionDispatch - # Makes a unique request id available to the action_dispatch.request_id env variable (which is then accessible through - # ActionDispatch::Request#uuid or the alias ActionDispatch::Request#request_id) and sends the same id to the client via the X-Request-Id header. + # Makes a unique request id available to the +action_dispatch.request_id+ env variable (which is then accessible + # through <tt>ActionDispatch::Request#request_id</tt> or the alias <tt>ActionDispatch::Request#uuid</tt>) and sends + # the same id to the client via the X-Request-Id header. # # The unique request id is either based on the X-Request-Id header in the request, which would typically be generated # by a firewall, load balancer, or the web server, or, if this header is not available, a random uuid. If the @@ -12,7 +13,7 @@ module ActionDispatch # The unique request id can be used to trace a request end-to-end and would typically end up being part of log files # from multiple pieces of the stack. class RequestId - X_REQUEST_ID = "X-Request-Id".freeze # :nodoc: + X_REQUEST_ID = "X-Request-Id".freeze #:nodoc: def initialize(app) @app = app diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index 60920ea6c8..49b82e7128 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -7,22 +7,12 @@ require "action_dispatch/request/session" module ActionDispatch module Session class SessionRestoreError < StandardError #:nodoc: - def initialize(const_error = nil) - if const_error - ActiveSupport::Deprecation.warn("Passing #original_exception is deprecated and has no effect. " \ - "Exceptions will automatically capture the original exception.", caller) - end - + def initialize super("Session contains objects whose class definition isn't available.\n" + "Remember to require the classes for all objects kept in the session.\n" + "(Original exception: #{$!.message} [#{$!.class}])\n") set_backtrace $!.backtrace end - - def original_exception - ActiveSupport::Deprecation.warn("#original_exception is deprecated. Use #cause instead.", caller) - cause - end end module Compatibility diff --git a/actionpack/lib/action_dispatch/middleware/ssl.rb b/actionpack/lib/action_dispatch/middleware/ssl.rb index 992daab3aa..c9bd417aa2 100644 --- a/actionpack/lib/action_dispatch/middleware/ssl.rb +++ b/actionpack/lib/action_dispatch/middleware/ssl.rb @@ -45,35 +45,17 @@ module ActionDispatch HSTS_EXPIRES_IN = 15552000 def self.default_hsts_options - { expires: HSTS_EXPIRES_IN, subdomains: false, preload: false } + { expires: HSTS_EXPIRES_IN, subdomains: true, preload: false } end - def initialize(app, redirect: {}, hsts: {}, secure_cookies: true, **options) + def initialize(app, redirect: {}, hsts: {}, secure_cookies: true) @app = app - if options[:host] || options[:port] - ActiveSupport::Deprecation.warn <<-end_warning.strip_heredoc - The `:host` and `:port` options are moving within `:redirect`: - `config.ssl_options = { redirect: { host: …, port: … } }`. - end_warning - @redirect = options.slice(:host, :port) - else - @redirect = redirect - end + @redirect = redirect @exclude = @redirect && @redirect[:exclude] || proc { !@redirect } @secure_cookies = secure_cookies - if hsts != true && hsts != false && hsts[:subdomains].nil? - hsts[:subdomains] = false - - ActiveSupport::Deprecation.warn <<-end_warning.strip_heredoc - In Rails 5.1, The `:subdomains` option of HSTS config will be treated as true if - unspecified. Set `config.ssl_options = { hsts: { subdomains: false } }` to opt out - of this behavior. - end_warning - end - @hsts_header = build_hsts_header(normalize_hsts_options(hsts)) end diff --git a/actionpack/lib/action_dispatch/middleware/stack.rb b/actionpack/lib/action_dispatch/middleware/stack.rb index 466eb8b3f1..6949b31e75 100644 --- a/actionpack/lib/action_dispatch/middleware/stack.rb +++ b/actionpack/lib/action_dispatch/middleware/stack.rb @@ -88,7 +88,6 @@ module ActionDispatch end def delete(target) - target = get_class target middlewares.delete_if { |m| m.klass == target } end @@ -103,31 +102,13 @@ module ActionDispatch private def assert_index(index, where) - index = get_class index i = index.is_a?(Integer) ? index : middlewares.index { |m| m.klass == index } raise "No such middleware to insert #{where}: #{index.inspect}" unless i i end - def get_class(klass) - if klass.is_a?(String) || klass.is_a?(Symbol) - classcache = ActiveSupport::Dependencies::Reference - converted_klass = classcache[klass.to_s] - ActiveSupport::Deprecation.warn <<-eowarn -Passing strings or symbols to the middleware builder is deprecated, please change -them to actual class references. For example: - - "#{klass}" => #{converted_klass} - - eowarn - converted_klass - else - klass - end - end - def build_middleware(klass, args, block) - Middleware.new(get_class(klass), args, block) + Middleware.new(klass, args, block) end end end diff --git a/actionpack/lib/action_dispatch/middleware/static.rb b/actionpack/lib/action_dispatch/middleware/static.rb index fbf2a5fd0b..5c71f0fc48 100644 --- a/actionpack/lib/action_dispatch/middleware/static.rb +++ b/actionpack/lib/action_dispatch/middleware/static.rb @@ -106,14 +106,7 @@ module ActionDispatch # produce a directory traversal using this middleware. Only 'GET' and 'HEAD' # requests will result in a file being returned. class Static - def initialize(app, path, deprecated_cache_control = :not_set, index: "index", headers: {}) - if deprecated_cache_control != :not_set - ActiveSupport::Deprecation.warn("The `cache_control` argument is deprecated," \ - "replaced by `headers: { 'Cache-Control' => #{deprecated_cache_control} }`, " \ - " and will be removed in Rails 5.1.") - headers["Cache-Control".freeze] = deprecated_cache_control - end - + def initialize(app, path, index: "index", headers: {}) @app = app @file_handler = FileHandler.new(path, index: index, headers: headers) end diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 4ec1b8ee1f..c481c190bf 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -1558,11 +1558,7 @@ module ActionDispatch options = path path, to = options.find { |name, _value| name.is_a?(String) } - if path.nil? - ActiveSupport::Deprecation.warn "Omitting the route path is deprecated. "\ - "Specify the path with a String or a Symbol instead." - path = "" - end + raise ArgumentError, "Route path not specified" if path.nil? case to when Symbol @@ -1844,18 +1840,7 @@ module ActionDispatch path_types.fetch(String, []).each do |_path| route_options = options.dup if _path && option_path - ActiveSupport::Deprecation.warn <<-eowarn -Specifying strings for both :path and the route path is deprecated. Change things like this: - - match #{_path.inspect}, :path => #{option_path.inspect} - -to this: - - match #{option_path.inspect}, :as => #{_path.inspect}, :action => #{_path.inspect} - eowarn - route_options[:action] = _path - route_options[:as] = _path - _path = option_path + raise ArgumentError, "Ambigous route definition. Both :path and the route path where specified as strings." end to = get_to_from_path(_path, to, route_options[:action]) decomposed_match(_path, controller, route_options, _path, to, via, formatted, anchor, options_constraints) diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 5abf59402d..a1bc357c8b 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -210,7 +210,7 @@ module ActionDispatch } constraints = Hash[@route.requirements.merge(params).sort_by { |k,v| k.to_s }] message = "No route matches #{constraints.inspect}" - message << " missing required keys: #{missing_keys.sort.inspect}" + message << ", missing required keys: #{missing_keys.sort.inspect}" raise ActionController::UrlGenerationError, message end diff --git a/actionpack/lib/action_dispatch/testing/integration.rb b/actionpack/lib/action_dispatch/testing/integration.rb index 720651fa1f..d137473ef4 100644 --- a/actionpack/lib/action_dispatch/testing/integration.rb +++ b/actionpack/lib/action_dispatch/testing/integration.rb @@ -38,72 +38,40 @@ module ActionDispatch # # get '/feed', params: { since: 201501011400 } # post '/profile', headers: { "X-Test-Header" => "testvalue" } - def get(path, *args) - process_with_kwargs(:get, path, *args) + def get(path, **args) + process(:get, path, **args) end # Performs a POST request with the given parameters. See +#get+ for more # details. - def post(path, *args) - process_with_kwargs(:post, path, *args) + def post(path, **args) + process(:post, path, **args) end # Performs a PATCH request with the given parameters. See +#get+ for more # details. - def patch(path, *args) - process_with_kwargs(:patch, path, *args) + def patch(path, **args) + process(:patch, path, **args) end # Performs a PUT request with the given parameters. See +#get+ for more # details. - def put(path, *args) - process_with_kwargs(:put, path, *args) + def put(path, **args) + process(:put, path, **args) end # Performs a DELETE request with the given parameters. See +#get+ for # more details. - def delete(path, *args) - process_with_kwargs(:delete, path, *args) + def delete(path, **args) + process(:delete, path, **args) end # Performs a HEAD request with the given parameters. See +#get+ for more # details. def head(path, *args) - process_with_kwargs(:head, path, *args) + process(:head, path, *args) end - # Performs an XMLHttpRequest request with the given parameters, mirroring - # an AJAX request made from JavaScript. - # - # The request_method is +:get+, +:post+, +:patch+, +:put+, +:delete+ or - # +:head+; the parameters are +nil+, a hash, or a url-encoded or multipart - # string; the headers are a hash. - # - # Example: - # - # xhr :get, '/feed', params: { since: 201501011400 } - def xml_http_request(request_method, path, *args) - if kwarg_request?(args) - params, headers, env = args.first.values_at(:params, :headers, :env) - else - params = args[0] - headers = args[1] - env = {} - - if params.present? || headers.present? - non_kwarg_request_warning - end - end - - ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc) - xhr and xml_http_request methods are deprecated in favor of - `get "/posts", xhr: true` and `post "/posts/1", xhr: true`. - MSG - - process(request_method, path, params: params, headers: headers, xhr: true) - end - alias xhr :xml_http_request - # Follow a single redirect response. If the last response was not a # redirect, an exception will be raised. Otherwise, the redirect is # performed on the location header. @@ -112,59 +80,6 @@ module ActionDispatch get(response.location) status end - - # Performs a request using the specified method, following any subsequent - # redirect. Note that the redirects are followed until the response is - # not a redirect--this means you may run into an infinite loop if your - # redirect loops back to itself. - # - # Example: - # - # request_via_redirect :post, '/welcome', - # params: { ref_id: 14 }, - # headers: { "X-Test-Header" => "testvalue" } - def request_via_redirect(http_method, path, *args) - ActiveSupport::Deprecation.warn("`request_via_redirect` is deprecated and will be removed in Rails 5.1. Please use `follow_redirect!` manually after the request call for the same behavior.") - process_with_kwargs(http_method, path, *args) - - follow_redirect! while redirect? - status - end - - # Performs a GET request, following any subsequent redirect. - # See +request_via_redirect+ for more information. - def get_via_redirect(path, *args) - ActiveSupport::Deprecation.warn("`get_via_redirect` is deprecated and will be removed in Rails 5.1. Please use `follow_redirect!` manually after the request call for the same behavior.") - request_via_redirect(:get, path, *args) - end - - # Performs a POST request, following any subsequent redirect. - # See +request_via_redirect+ for more information. - def post_via_redirect(path, *args) - ActiveSupport::Deprecation.warn("`post_via_redirect` is deprecated and will be removed in Rails 5.1. Please use `follow_redirect!` manually after the request call for the same behavior.") - request_via_redirect(:post, path, *args) - end - - # Performs a PATCH request, following any subsequent redirect. - # See +request_via_redirect+ for more information. - def patch_via_redirect(path, *args) - ActiveSupport::Deprecation.warn("`patch_via_redirect` is deprecated and will be removed in Rails 5.1. Please use `follow_redirect!` manually after the request call for the same behavior.") - request_via_redirect(:patch, path, *args) - end - - # Performs a PUT request, following any subsequent redirect. - # See +request_via_redirect+ for more information. - def put_via_redirect(path, *args) - ActiveSupport::Deprecation.warn("`put_via_redirect` is deprecated and will be removed in Rails 5.1. Please use `follow_redirect!` manually after the request call for the same behavior.") - request_via_redirect(:put, path, *args) - end - - # Performs a DELETE request, following any subsequent redirect. - # See +request_via_redirect+ for more information. - def delete_via_redirect(path, *args) - ActiveSupport::Deprecation.warn("`delete_via_redirect` is deprecated and will be removed in Rails 5.1. Please use `follow_redirect!` manually after the request call for the same behavior.") - request_via_redirect(:delete, path, *args) - end end # An instance of this class represents a set of requests and responses @@ -293,37 +208,6 @@ module ActionDispatch @_mock_session ||= Rack::MockSession.new(@app, host) end - def process_with_kwargs(http_method, path, *args) - if kwarg_request?(args) - process(http_method, path, *args) - else - non_kwarg_request_warning if args.any? - process(http_method, path, params: args[0], headers: args[1]) - end - end - - REQUEST_KWARGS = %i(params headers env xhr as) - def kwarg_request?(args) - args[0].respond_to?(:keys) && args[0].keys.any? { |k| REQUEST_KWARGS.include?(k) } - end - - def non_kwarg_request_warning - ActiveSupport::Deprecation.warn(<<-MSG.strip_heredoc) - ActionDispatch::IntegrationTest HTTP request methods will accept only - the following keyword arguments in future Rails versions: - #{REQUEST_KWARGS.join(', ')} - - Examples: - - get '/profile', - params: { id: 1 }, - headers: { 'X-Extra-Header' => '123' }, - env: { 'action_dispatch.custom' => 'custom' }, - xhr: true, - as: :json - MSG - end - # Performs the actual request. def process(method, path, params: nil, headers: nil, env: nil, xhr: false, as: nil) request_encoder = RequestEncoder.encoder(as) @@ -713,6 +597,8 @@ module ActionDispatch class IntegrationTest < ActiveSupport::TestCase include TestProcess + undef :assigns + module UrlOptions extend ActiveSupport::Concern def url_options diff --git a/actionpack/lib/action_dispatch/testing/test_process.rb b/actionpack/lib/action_dispatch/testing/test_process.rb index 1456a0afcf..8b03b776fa 100644 --- a/actionpack/lib/action_dispatch/testing/test_process.rb +++ b/actionpack/lib/action_dispatch/testing/test_process.rb @@ -34,7 +34,8 @@ module ActionDispatch # # post :change_avatar, avatar: fixture_file_upload('files/spongebob.png', 'image/png', :binary) def fixture_file_upload(path, mime_type = nil, binary = false) - if self.class.respond_to?(:fixture_path) && self.class.fixture_path + if self.class.respond_to?(:fixture_path) && self.class.fixture_path && + !File.exist?(path) path = File.join(self.class.fixture_path, path) end Rack::Test::UploadedFile.new(path, mime_type, binary) diff --git a/actionpack/lib/action_dispatch/testing/test_request.rb b/actionpack/lib/action_dispatch/testing/test_request.rb index d0beb72a41..91b25ec155 100644 --- a/actionpack/lib/action_dispatch/testing/test_request.rb +++ b/actionpack/lib/action_dispatch/testing/test_request.rb @@ -22,7 +22,7 @@ module ActionDispatch private_class_method :default_env def request_method=(method) - set_header("REQUEST_METHOD", method.to_s.upcase) + super(method.to_s.upcase) end def host=(host) diff --git a/actionpack/test/abstract/callbacks_test.rb b/actionpack/test/abstract/callbacks_test.rb index a0f2efa330..9c2261bf76 100644 --- a/actionpack/test/abstract/callbacks_test.rb +++ b/actionpack/test/abstract/callbacks_test.rb @@ -264,53 +264,5 @@ module AbstractController assert_equal "Hello world Howdy!", controller.response_body end end - - class AliasedCallbacks < ControllerWithCallbacks - ActiveSupport::Deprecation.silence do - before_filter :first - after_filter :second - around_filter :aroundz - end - - def first - @text = "Hello world" - end - - def second - @second = "Goodbye" - end - - def aroundz - @aroundz = "FIRST" - yield - @aroundz << "SECOND" - end - - def index - @text ||= nil - self.response_body = @text.to_s - end - end - - class TestAliasedCallbacks < ActiveSupport::TestCase - def setup - @controller = AliasedCallbacks.new - end - - test "before_filter works" do - @controller.process(:index) - assert_equal "Hello world", @controller.response_body - end - - test "after_filter works" do - @controller.process(:index) - assert_equal "Goodbye", @controller.instance_variable_get("@second") - end - - test "around_filter works" do - @controller.process(:index) - assert_equal "FIRSTSECOND", @controller.instance_variable_get("@aroundz") - end - end end end diff --git a/actionpack/test/controller/api/renderers_test.rb b/actionpack/test/controller/api/renderers_test.rb index 7eecc1c680..04e34a1f8f 100644 --- a/actionpack/test/controller/api/renderers_test.rb +++ b/actionpack/test/controller/api/renderers_test.rb @@ -23,10 +23,6 @@ class RenderersApiController < ActionController::API def plain render plain: "Hi from plain", status: 500 end - - def text - render text: "Hi from text", status: 500 - end end class RenderersApiTest < ActionController::TestCase @@ -49,12 +45,4 @@ class RenderersApiTest < ActionController::TestCase assert_response :internal_server_error assert_equal("Hi from plain", @response.body) end - - def test_render_text - assert_deprecated do - get :text - end - assert_response :internal_server_error - assert_equal("Hi from text", @response.body) - end end diff --git a/actionpack/test/controller/filters_test.rb b/actionpack/test/controller/filters_test.rb index e0987070a3..a34878cee8 100644 --- a/actionpack/test/controller/filters_test.rb +++ b/actionpack/test/controller/filters_test.rb @@ -2,7 +2,7 @@ require "abstract_unit" class ActionController::Base class << self - %w(append_around_action prepend_after_action prepend_around_action prepend_before_action skip_after_action skip_before_action skip_action_callback).each do |pending| + %w(append_around_action prepend_after_action prepend_around_action prepend_before_action skip_after_action skip_before_action).each do |pending| define_method(pending) do |*args| $stderr.puts "#{pending} unimplemented: #{args.inspect}" end unless method_defined?(pending) @@ -956,13 +956,6 @@ class ControllerWithTwoLessFilters < ControllerWithAllTypesOfFilters skip_after_action :after end -class SkipFilterUsingSkipActionCallback < ControllerWithAllTypesOfFilters - ActiveSupport::Deprecation.silence do - skip_action_callback :around_again - skip_action_callback :after - end -end - class YieldingAroundFiltersTest < ActionController::TestCase include PostsController::AroundExceptions @@ -1047,27 +1040,6 @@ class YieldingAroundFiltersTest < ActionController::TestCase assert_equal 3, controller.instance_variable_get(:@try) end - def test_skipping_with_skip_action_callback - test_process(SkipFilterUsingSkipActionCallback,"no_raise") - assert_equal "before around (before yield) around (after yield)", @controller.instance_variable_get(:@ran_filter).join(" ") - end - - def test_deprecated_skip_action_callback - assert_deprecated do - Class.new(PostsController) do - skip_action_callback :clean_up - end - end - end - - def test_deprecated_skip_filter - assert_deprecated do - Class.new(PostsController) do - skip_filter :clean_up - end - end - end - protected def test_process(controller, action = "show") @controller = controller.is_a?(Class) ? controller.new : controller diff --git a/actionpack/test/controller/integration_test.rb b/actionpack/test/controller/integration_test.rb index d3bc77d3ef..652c0f0dd2 100644 --- a/actionpack/test/controller/integration_test.rb +++ b/actionpack/test/controller/integration_test.rb @@ -31,95 +31,6 @@ class SessionTest < ActiveSupport::TestCase end end - def test_request_via_redirect_uses_given_method - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - assert_called_with @session, :process, [:put, path, params: args, headers: headers] do - @session.stub :redirect?, false do - assert_deprecated { @session.request_via_redirect(:put, path, params: args, headers: headers) } - end - end - end - - def test_deprecated_request_via_redirect_uses_given_method - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - assert_called_with @session, :process, [:put, path, params: args, headers: headers] do - @session.stub :redirect?, false do - assert_deprecated { @session.request_via_redirect(:put, path, args, headers) } - end - end - end - - def test_request_via_redirect_follows_redirects - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - value_series = [true, true, false] - assert_called @session, :follow_redirect!, times: 2 do - @session.stub :redirect?, -> { value_series.shift } do - assert_deprecated { @session.request_via_redirect(:get, path, params: args, headers: headers) } - end - end - end - - def test_request_via_redirect_returns_status - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - @session.stub :redirect?, false do - @session.stub :status, 200 do - assert_deprecated do - assert_equal 200, @session.request_via_redirect(:get, path, params: args, headers: headers) - end - end - end - end - - def test_deprecated_get_via_redirect - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - - assert_called_with @session, :request_via_redirect, [:get, path, args, headers] do - assert_deprecated do - @session.get_via_redirect(path, args, headers) - end - end - end - - def test_deprecated_post_via_redirect - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - - assert_called_with @session, :request_via_redirect, [:post, path, args, headers] do - assert_deprecated do - @session.post_via_redirect(path, args, headers) - end - end - end - - def test_deprecated_patch_via_redirect - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - - assert_called_with @session, :request_via_redirect, [:patch, path, args, headers] do - assert_deprecated do - @session.patch_via_redirect(path, args, headers) - end - end - end - - def test_deprecated_put_via_redirect - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - - assert_called_with @session, :request_via_redirect, [:put, path, args, headers] do - assert_deprecated do - @session.put_via_redirect(path, args, headers) - end - end - end - - def test_deprecated_delete_via_redirect - path = "/somepath"; args = { id: "1" }; headers = { "X-Test-Header" => "testvalue" } - - assert_called_with @session, :request_via_redirect, [:delete, path, args, headers] do - assert_deprecated do - @session.delete_via_redirect(path, args, headers) - end - end - end - def test_get path = "/index"; params = "blah"; headers = { location: "blah" } @@ -135,28 +46,9 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_get - path = "/index"; params = "blah"; headers = { location: "blah" } - - assert_called_with @session, :process, [:get, path, params: params, headers: headers] do - assert_deprecated { - @session.get(path, params, headers) - } - end - end - def test_post path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:post, path, params: params, headers: headers] do - assert_deprecated { - @session.post(path, params, headers) - } - end - end - - def test_deprecated_post - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:post, path, params: params, headers: headers] do @session.post(path, params: params, headers: headers) end end @@ -168,15 +60,6 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_patch - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:patch, path, params: params, headers: headers] do - assert_deprecated { - @session.patch(path, params, headers) - } - end - end - def test_put path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:put, path, params: params, headers: headers] do @@ -184,27 +67,9 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_put - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:put, path, params: params, headers: headers] do - assert_deprecated { - @session.put(path, params, headers) - } - end - end - def test_delete path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:delete, path, params: params, headers: headers] do - assert_deprecated { - @session.delete(path,params,headers) - } - end - end - - def test_deprecated_delete - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:delete, path, params: params, headers: headers] do @session.delete(path, params: params, headers: headers) end end @@ -216,15 +81,6 @@ class SessionTest < ActiveSupport::TestCase end end - def deprecated_test_head - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:head, path, params: params, headers: headers] do - assert_deprecated { - @session.head(path, params, headers) - } - end - end - def test_xml_http_request_get path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:get, path, params: params, headers: headers, xhr: true] do @@ -232,22 +88,6 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_xml_http_request_get - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:get, path, params: params, headers: headers, xhr: true] do - @session.get(path, params: params, headers: headers, xhr: true) - end - end - - def test_deprecated_args_xml_http_request_get - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:get, path, params: params, headers: headers, xhr: true] do - assert_deprecated(/xml_http_request/) { - @session.xml_http_request(:get, path, params, headers) - } - end - end - def test_xml_http_request_post path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:post, path, params: params, headers: headers, xhr: true] do @@ -255,20 +95,6 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_xml_http_request_post - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:post, path, params: params, headers: headers, xhr: true] do - @session.post(path, params: params, headers: headers, xhr: true) - end - end - - def test_deprecated_args_xml_http_request_post - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:post, path, params: params, headers: headers, xhr: true] do - assert_deprecated(/xml_http_request/) { @session.xml_http_request(:post,path,params,headers) } - end - end - def test_xml_http_request_patch path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:patch, path, params: params, headers: headers, xhr: true] do @@ -276,20 +102,6 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_xml_http_request_patch - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:patch, path, params: params, headers: headers, xhr: true] do - @session.patch(path, params: params, headers: headers, xhr: true) - end - end - - def test_deprecated_args_xml_http_request_patch - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:patch, path, params: params, headers: headers, xhr: true] do - assert_deprecated(/xml_http_request/) { @session.xml_http_request(:patch,path,params,headers) } - end - end - def test_xml_http_request_put path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:put, path, params: params, headers: headers, xhr: true] do @@ -297,20 +109,6 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_xml_http_request_put - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:put, path, params: params, headers: headers, xhr: true] do - @session.put(path, params: params, headers: headers, xhr: true) - end - end - - def test_deprecated_args_xml_http_request_put - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:put, path, params: params, headers: headers, xhr: true] do - assert_deprecated(/xml_http_request/) { @session.xml_http_request(:put, path, params, headers) } - end - end - def test_xml_http_request_delete path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:delete, path, params: params, headers: headers, xhr: true] do @@ -318,40 +116,12 @@ class SessionTest < ActiveSupport::TestCase end end - def test_deprecated_xml_http_request_delete - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:delete, path, params: params, headers: headers, xhr: true] do - assert_deprecated { @session.xml_http_request(:delete, path, params: params, headers: headers) } - end - end - - def test_deprecated_args_xml_http_request_delete - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:delete, path, params: params, headers: headers, xhr: true] do - assert_deprecated(/xml_http_request/) { @session.xml_http_request(:delete, path, params, headers) } - end - end - def test_xml_http_request_head path = "/index"; params = "blah"; headers = { location: "blah" } assert_called_with @session, :process, [:head, path, params: params, headers: headers, xhr: true] do @session.head(path, params: params, headers: headers, xhr: true) end end - - def test_deprecated_xml_http_request_head - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:head, path, params: params, headers: headers, xhr: true] do - assert_deprecated(/xml_http_request/) { @session.xml_http_request(:head, path, params: params, headers: headers) } - end - end - - def test_deprecated_args_xml_http_request_head - path = "/index"; params = "blah"; headers = { location: "blah" } - assert_called_with @session, :process, [:head, path, params: params, headers: headers, xhr: true] do - assert_deprecated { @session.xml_http_request(:head, path, params, headers) } - end - end end class IntegrationTestTest < ActiveSupport::TestCase @@ -383,6 +153,14 @@ class IntegrationTestTest < ActiveSupport::TestCase mixin.__send__(:remove_method, :method_missing) end end + + def test_assigns_is_undefined_and_not_point_to_the_gem + e = assert_raises(NoMethodError) do + @test.assigns(:foo) + end + + assert_match(/undefined method/, e.message) + end end # Tests that integration tests don't call Controller test methods for processing. @@ -577,18 +355,6 @@ class IntegrationProcessTest < ActionDispatch::IntegrationTest end end - def test_deprecated_xml_http_request_get - with_test_route_set do - assert_deprecated { xhr :get, "/get" } - assert_equal 200, status - assert_equal "OK", status_message - assert_response 200 - assert_response :success - assert_response :ok - assert_equal "JS OK", response.body - end - end - def test_request_with_bad_format with_test_route_set do get "/get.php", xhr: true diff --git a/actionpack/test/controller/live_stream_test.rb b/actionpack/test/controller/live_stream_test.rb index 1361e95081..e76628b936 100644 --- a/actionpack/test/controller/live_stream_test.rb +++ b/actionpack/test/controller/live_stream_test.rb @@ -157,7 +157,9 @@ module ActionController response.headers["Content-Type"] = "text/event-stream" response.stream.write "before load" sleep 0.01 - ::LoadMe + silence_warning do + ::LoadMe + end response.stream.close latch.count_down diff --git a/actionpack/test/controller/new_base/render_text_test.rb b/actionpack/test/controller/new_base/render_text_test.rb deleted file mode 100644 index 6f55c497b4..0000000000 --- a/actionpack/test/controller/new_base/render_text_test.rb +++ /dev/null @@ -1,188 +0,0 @@ -require "abstract_unit" - -module RenderText - class MinimalController < ActionController::Metal - include AbstractController::Rendering - include ActionController::Rendering - - def index - render text: "Hello World!" - end - end - - class SimpleController < ActionController::Base - self.view_paths = [ActionView::FixtureResolver.new] - - def index - render text: "hello david" - end - end - - class WithLayoutController < ::ApplicationController - self.view_paths = [ActionView::FixtureResolver.new( - "layouts/application.html.erb" => "<%= yield %>, I'm here!", - "layouts/greetings.html.erb" => "<%= yield %>, I wish thee well.", - "layouts/ivar.html.erb" => "<%= yield %>, <%= @ivar %>" - )] - - def index - render text: "hello david" - end - - def custom_code - render text: "hello world", status: 404 - end - - def with_custom_code_as_string - render text: "hello world", status: "404 Not Found" - end - - def with_nil - render text: nil - end - - def with_nil_and_status - render text: nil, status: 403 - end - - def with_false - render text: false - end - - def with_layout_true - render text: "hello world", layout: true - end - - def with_layout_false - render text: "hello world", layout: false - end - - def with_layout_nil - render text: "hello world", layout: nil - end - - def with_custom_layout - render text: "hello world", layout: "greetings" - end - - def with_ivar_in_layout - @ivar = "hello world" - render text: "hello world", layout: "ivar" - end - end - - class RenderTextTest < Rack::TestCase - test "rendering text from a minimal controller" do - ActiveSupport::Deprecation.silence do - get "/render_text/minimal/index" - end - - assert_body "Hello World!" - assert_status 200 - end - - test "rendering text from an action with default options renders the text with the layout" do - with_routing do |set| - set.draw { ActiveSupport::Deprecation.silence { get ":controller", action: "index" } } - - ActiveSupport::Deprecation.silence do - get "/render_text/simple" - end - - assert_body "hello david" - assert_status 200 - end - end - - test "rendering text from an action with default options renders the text without the layout" do - with_routing do |set| - set.draw { ActiveSupport::Deprecation.silence { get ":controller", action: "index" } } - - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout" - end - - assert_body "hello david" - assert_status 200 - end - end - - test "rendering text, while also providing a custom status code" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/custom_code" - end - - assert_body "hello world" - assert_status 404 - end - - test "rendering text with nil returns an empty body" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/with_nil" - end - - assert_body "" - assert_status 200 - end - - test "Rendering text with nil and custom status code returns an empty body and the status" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/with_nil_and_status" - end - - assert_body "" - assert_status 403 - end - - test "rendering text with false returns the string 'false'" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/with_false" - end - - assert_body "false" - assert_status 200 - end - - test "rendering text with layout: true" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/with_layout_true" - end - - assert_body "hello world, I'm here!" - assert_status 200 - end - - test "rendering text with layout: 'greetings'" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/with_custom_layout" - end - - assert_body "hello world, I wish thee well." - assert_status 200 - end - - test "rendering text with layout: false" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/with_layout_false" - end - - assert_body "hello world" - assert_status 200 - end - - test "rendering text with layout: nil" do - ActiveSupport::Deprecation.silence do - get "/render_text/with_layout/with_layout_nil" - end - - assert_body "hello world" - assert_status 200 - end - - test "rendering text displays deprecation warning" do - assert_deprecated do - get "/render_text/with_layout/with_layout_nil" - end - end - end -end diff --git a/actionpack/test/controller/parameters/accessors_test.rb b/actionpack/test/controller/parameters/accessors_test.rb index 8a522b2df8..2893eb7b91 100644 --- a/actionpack/test/controller/parameters/accessors_test.rb +++ b/actionpack/test/controller/parameters/accessors_test.rb @@ -131,14 +131,6 @@ class ParametersAccessorsTest < ActiveSupport::TestCase assert_not @params[:person].values_at(:name).first.permitted? end - test "equality with a hash is deprecated" do - hash1 = { foo: :bar } - params1 = ActionController::Parameters.new(hash1) - assert_deprecated("will be removed in Rails 5.1") do - assert(params1 == hash1) - end - end - test "is equal to Parameters instance with same params" do params1 = ActionController::Parameters.new(a: 1, b: 2) params2 = ActionController::Parameters.new(a: 1, b: 2) diff --git a/actionpack/test/controller/redirect_test.rb b/actionpack/test/controller/redirect_test.rb index 495e41ce76..0e61b92bcf 100644 --- a/actionpack/test/controller/redirect_test.rb +++ b/actionpack/test/controller/redirect_test.rb @@ -56,10 +56,6 @@ class RedirectController < ActionController::Base redirect_to("/things/stuff", status: 301) end - def redirect_to_back_with_status - redirect_to :back, status: 307 - end - def redirect_back_with_status redirect_back(fallback_location: "/things/stuff", status: 307) end @@ -88,10 +84,6 @@ class RedirectController < ActionController::Base redirect_to "//www.rubyonrails.org/" end - def redirect_to_back - redirect_to :back - end - def redirect_to_existing_record redirect_to Workshop.new(5) end @@ -206,17 +198,6 @@ class RedirectTest < ActionController::TestCase assert_equal "http://test.host/things/stuff", redirect_to_url end - def test_redirect_to_back_with_status - @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" - - assert_deprecated do - get :redirect_to_back_with_status - end - - assert_response 307 - assert_equal "http://www.example.com/coming/from", redirect_to_url - end - def test_simple_redirect_using_options get :host_redirect assert_response :redirect @@ -259,29 +240,6 @@ class RedirectTest < ActionController::TestCase assert_equal "//www.rubyonrails.org/", redirect_to_url end - def test_redirect_to_back - @request.env["HTTP_REFERER"] = "http://www.example.com/coming/from" - - assert_deprecated do - get :redirect_to_back - end - - assert_response :redirect - assert_equal "http://www.example.com/coming/from", redirect_to_url - end - - def test_redirect_to_back_with_no_referer - assert_raise(ActionController::RedirectBackError) { - @request.env["HTTP_REFERER"] = nil - - assert_deprecated do - get :redirect_to_back - end - - get :redirect_to_back - } - end - def test_redirect_back referer = "http://www.example.com/coming/from" @request.env["HTTP_REFERER"] = referer diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 70e5760764..76139d59e2 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -160,10 +160,6 @@ class TestController < ActionController::Base render action: "hello_world" end - def respond_with_empty_body - render nothing: true - end - def conditional_hello_with_bangs render action: "hello_world" end @@ -173,14 +169,6 @@ class TestController < ActionController::Base fresh_when(last_modified: Time.now.utc.beginning_of_day, etag: [ :foo, 123 ]) end - def head_with_status_hash - head status: :created - end - - def head_with_hash_does_not_include_status - head warning: :deprecated - end - def head_created head :created end @@ -379,12 +367,6 @@ class ExpiresInRenderTest < ActionController::TestCase assert_match(/no-transform/, @response.headers["Cache-Control"]) end - def test_render_nothing_deprecated - assert_deprecated do - get :respond_with_empty_body - end - end - def test_date_header_when_expires_in time = Time.mktime(2011,10,30) Time.stub :now, time do @@ -670,19 +652,6 @@ class HeadRenderTest < ActionController::TestCase assert_response :created end - def test_passing_hash_to_head_as_first_parameter_deprecated - assert_deprecated do - get :head_with_status_hash - end - end - - def test_head_with_default_value_is_deprecated - assert_deprecated do - get :head_with_hash_does_not_include_status - assert_response :ok - end - end - def test_head_created_with_application_json_content_type post :head_created_with_application_json_content_type assert @response.body.blank? diff --git a/actionpack/test/controller/required_params_test.rb b/actionpack/test/controller/required_params_test.rb index 9fa2b6dbb0..dd07c2486b 100644 --- a/actionpack/test/controller/required_params_test.rb +++ b/actionpack/test/controller/required_params_test.rb @@ -72,14 +72,8 @@ class ParametersRequireTest < ActiveSupport::TestCase assert params.value?("cinco") end - test "Deprecated methods are deprecated" do - assert_deprecated do - ActionController::Parameters.new(foo: "bar").merge!(bar: "foo") - end - end - test "to_query is not supported" do - assert_deprecated do + assert_raises(NoMethodError) do ActionController::Parameters.new(foo: "bar").to_param end end diff --git a/actionpack/test/controller/test_case_test.rb b/actionpack/test/controller/test_case_test.rb index 696794a3eb..82f42e306f 100644 --- a/actionpack/test/controller/test_case_test.rb +++ b/actionpack/test/controller/test_case_test.rb @@ -229,14 +229,6 @@ XML assert_equal params.to_query, @response.body end - def test_deprecated_body_stream - params = Hash[:page, { name: "page name" }, "some key", 123] - - assert_deprecated { post :render_body, params.dup } - - assert_equal params.to_query, @response.body - end - def test_document_body_and_params_with_post post :test_params, params: { id: 1 } assert_equal({ "id"=>"1", "controller"=>"test_case_test/test", "action"=>"test_params" }, ::JSON.parse(@response.body)) @@ -247,21 +239,11 @@ XML assert_equal "document body", @response.body end - def test_deprecated_document_body_with_post - assert_deprecated { post :render_body, "document body" } - assert_equal "document body", @response.body - end - def test_document_body_with_put put :render_body, body: "document body" assert_equal "document body", @response.body end - def test_deprecated_document_body_with_put - assert_deprecated { put :render_body, "document body" } - assert_equal "document body", @response.body - end - def test_head head :test_params assert_equal 200, @response.status @@ -272,11 +254,6 @@ XML assert_equal "><", flash["test"] end - def test_deprecated_process_with_flash - assert_deprecated { process :set_flash, "GET", nil, nil, "test" => "value" } - assert_equal ">value<", flash["test"] - end - def test_process_with_flash process :set_flash, method: "GET", @@ -284,11 +261,6 @@ XML assert_equal ">value<", flash["test"] end - def test_deprecated_process_with_flash_now - assert_deprecated { process :set_flash_now, "GET", nil, nil, "test_now" => "value_now" } - assert_equal ">value_now<", flash["test_now"] - end - def test_process_with_flash_now process :set_flash_now, method: "GET", @@ -311,14 +283,6 @@ XML assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access" end - def test_process_with_session_arg - assert_deprecated { process :no_op, "GET", nil, "string" => "value1", symbol: "value2" } - assert_equal "value1", session["string"] - assert_equal "value1", session[:string] - assert_equal "value2", session["symbol"] - assert_equal "value2", session[:symbol] - end - def test_process_with_session_kwarg process :no_op, method: "GET", session: { "string" => "value1", symbol: "value2" } assert_equal "value1", session["string"] @@ -327,15 +291,6 @@ XML assert_equal "value2", session[:symbol] end - def test_deprecated_process_merges_session_arg - session[:foo] = "bar" - assert_deprecated { - get :no_op, nil, bar: "baz" - } - assert_equal "bar", session[:foo] - assert_equal "baz", session[:bar] - end - def test_process_merges_session_arg session[:foo] = "bar" get :no_op, session: { bar: "baz" } @@ -343,15 +298,6 @@ XML assert_equal "baz", session[:bar] end - def test_deprecated_merged_session_arg_is_retained_across_requests - assert_deprecated { - get :no_op, nil, foo: "bar" - } - assert_equal "bar", session[:foo] - get :no_op - assert_equal "bar", session[:foo] - end - def test_merged_session_arg_is_retained_across_requests get :no_op, session: { foo: "bar" } assert_equal "bar", session[:foo] @@ -393,11 +339,6 @@ XML assert_equal "/test_case_test/test/test_uri", @response.body end - def test_deprecated_process_with_request_uri_with_params - assert_deprecated { process :test_uri, "GET", id: 7 } - assert_equal "/test_case_test/test/test_uri/7", @response.body - end - def test_process_with_request_uri_with_params process :test_uri, method: "GET", @@ -406,12 +347,6 @@ XML assert_equal "/test_case_test/test/test_uri/7", @response.body end - def test_deprecated_process_with_request_uri_with_params_with_explicit_uri - @request.env["PATH_INFO"] = "/explicit/uri" - assert_deprecated { process :test_uri, "GET", id: 7 } - assert_equal "/explicit/uri", @response.body - end - def test_process_with_request_uri_with_params_with_explicit_uri @request.env["PATH_INFO"] = "/explicit/uri" process :test_uri, method: "GET", params: { id: 7 } @@ -491,20 +426,6 @@ XML end end - def test_deprecated_params_passing - assert_deprecated { - get :test_params, page: { name: "Page name", month: "4", year: "2004", day: "6" } - } - parsed_params = ::JSON.parse(@response.body) - assert_equal( - { - "controller" => "test_case_test/test", "action" => "test_params", - "page" => { "name" => "Page name", "month" => "4", "year" => "2004", "day" => "6" } - }, - parsed_params - ) - end - def test_params_passing get :test_params, params: { page: { @@ -589,16 +510,6 @@ XML ) end - def test_deprecated_params_passing_path_parameter_is_string_when_not_html_request - assert_deprecated { get :test_params, format: "json", id: 1 } - parsed_params = ::JSON.parse(@response.body) - assert_equal( - { "controller" => "test_case_test/test", "action" => "test_params", - "format" => "json", "id" => "1" }, - parsed_params - ) - end - def test_params_passing_with_frozen_values assert_nothing_raised do get :test_params, params: { @@ -646,6 +557,11 @@ XML assert_equal 2, @request.request_parameters[:num_value] end + def test_using_as_json_sets_format_json + post :render_body, params: { bool_value: true, str_value: "string", num_value: 2 }, as: :json + assert_equal "json", @request.format + end + def test_mutating_content_type_headers_for_plain_text_files_sets_the_header @request.headers["Content-Type"] = "text/plain" post :render_body, params: { name: "foo.txt" } @@ -678,11 +594,6 @@ XML assert_kind_of String, @request.path_parameters[:id] end - def test_deprecared_id_converted_to_string - assert_deprecated { get :test_params, id: 20, foo: Object.new } - assert_kind_of String, @request.path_parameters[:id] - end - def test_array_path_parameter_handled_properly with_routing do |set| set.draw do @@ -737,12 +648,6 @@ XML assert_nil @request.env["HTTP_ACCEPT"] end - def test_deprecated_xhr_with_params - assert_deprecated { xhr :get, :test_params, params: { id: 1 } } - - assert_equal({ "id"=>"1", "controller"=>"test_case_test/test", "action"=>"test_params" }, ::JSON.parse(@response.body)) - end - def test_xhr_with_params get :test_params, params: { id: 1 }, xhr: true @@ -758,23 +663,6 @@ XML assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access" end - def test_deprecated_xhr_with_session - assert_deprecated { xhr :get, :set_session } - - assert_equal "A wonder", session["string"], "A value stored in the session should be available by string key" - assert_equal "A wonder", session[:string], "Test session hash should allow indifferent access" - assert_equal "it works", session["symbol"], "Test session hash should allow indifferent access" - assert_equal "it works", session[:symbol], "Test session hash should allow indifferent access" - end - - def test_deprecated_params_reset_between_post_requests - assert_deprecated { post :no_op, foo: "bar" } - assert_equal "bar", @request.params[:foo] - - post :no_op - assert @request.params[:foo].blank? - end - def test_params_reset_between_post_requests post :no_op, params: { foo: "bar" } assert_equal "bar", @request.params[:foo] @@ -962,20 +850,18 @@ XML end end + def test_fixture_file_upload_ignores_fixture_path_given_full_path + TestCaseTest.stub :fixture_path, File.dirname(__FILE__) do + uploaded_file = fixture_file_upload("#{FILES_DIR}/mona_lisa.jpg", "image/jpg") + assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read + end + end + def test_fixture_file_upload_ignores_nil_fixture_path uploaded_file = fixture_file_upload("#{FILES_DIR}/mona_lisa.jpg", "image/jpg") assert_equal File.open("#{FILES_DIR}/mona_lisa.jpg", READ_PLAIN).read, uploaded_file.read end - def test_deprecated_action_dispatch_uploaded_file_upload - filename = "mona_lisa.jpg" - path = "#{FILES_DIR}/#{filename}" - assert_deprecated { - post :test_file_upload, file: Rack::Test::UploadedFile.new(path, "image/jpg", true) - } - assert_equal "159528", @response.body - end - def test_action_dispatch_uploaded_file_upload filename = "mona_lisa.jpg" path = "#{FILES_DIR}/#{filename}" diff --git a/actionpack/test/dispatch/middleware_stack_test.rb b/actionpack/test/dispatch/middleware_stack_test.rb index 27da5935b5..481aa22b10 100644 --- a/actionpack/test/dispatch/middleware_stack_test.rb +++ b/actionpack/test/dispatch/middleware_stack_test.rb @@ -18,14 +18,6 @@ class MiddlewareStackTest < ActiveSupport::TestCase @stack.use BarMiddleware end - def test_delete_with_string_is_deprecated - assert_deprecated do - assert_difference "@stack.size", -1 do - @stack.delete FooMiddleware.name - end - end - end - def test_delete_works assert_difference "@stack.size", -1 do @stack.delete FooMiddleware @@ -39,24 +31,6 @@ class MiddlewareStackTest < ActiveSupport::TestCase assert_equal BazMiddleware, @stack.last.klass end - test "use should push middleware as a string onto the stack" do - assert_deprecated do - assert_difference "@stack.size" do - @stack.use "MiddlewareStackTest::BazMiddleware" - end - assert_equal BazMiddleware, @stack.last.klass - end - end - - test "use should push middleware as a symbol onto the stack" do - assert_deprecated do - assert_difference "@stack.size" do - @stack.use :"MiddlewareStackTest::BazMiddleware" - end - assert_equal BazMiddleware, @stack.last.klass - end - end - test "use should push middleware class with arguments onto the stack" do assert_difference "@stack.size" do @stack.use BazMiddleware, true, foo: "bar" @@ -107,10 +81,8 @@ class MiddlewareStackTest < ActiveSupport::TestCase end test "unshift adds a new middleware at the beginning of the stack" do - assert_deprecated do - @stack.unshift :"MiddlewareStackTest::BazMiddleware" - assert_equal BazMiddleware, @stack.first.klass - end + @stack.unshift MiddlewareStackTest::BazMiddleware + assert_equal BazMiddleware, @stack.first.klass end test "raise an error on invalid index" do @@ -123,15 +95,6 @@ class MiddlewareStackTest < ActiveSupport::TestCase end end - test "lazy evaluates middleware class" do - assert_deprecated do - assert_difference "@stack.size" do - @stack.use "MiddlewareStackTest::BazMiddleware" - end - assert_equal BazMiddleware, @stack.last.klass - end - end - test "can check if Middleware are equal - Class" do assert_equal @stack.last, BarMiddleware end diff --git a/actionpack/test/dispatch/mime_type_test.rb b/actionpack/test/dispatch/mime_type_test.rb index 421ae6e133..e558efb88d 100644 --- a/actionpack/test/dispatch/mime_type_test.rb +++ b/actionpack/test/dispatch/mime_type_test.rb @@ -167,18 +167,6 @@ class MimeTypeTest < ActiveSupport::TestCase end end - test "deprecated lookup" do - assert_deprecated do - Mime::HTML - end - end - - test "deprecated const_defined?" do - assert_deprecated do - Mime.const_defined? :HTML - end - end - test "references gives preference to symbols before strings" do assert_equal :html, Mime[:html].ref another = Mime::Type.lookup("foo/bar") diff --git a/actionpack/test/dispatch/request/json_params_parsing_test.rb b/actionpack/test/dispatch/request/json_params_parsing_test.rb index d0cd32a242..10234a4815 100644 --- a/actionpack/test/dispatch/request/json_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/json_params_parsing_test.rb @@ -75,7 +75,9 @@ class JsonParamsParsingTest < ActionDispatch::IntegrationTest begin $stderr = StringIO.new # suppress the log json = "[\"person]\": {\"name\": \"David\"}}" - exception = assert_raise(ActionDispatch::ParamsParser::ParseError) { post "/parse", json, "CONTENT_TYPE" => "application/json", "action_dispatch.show_exceptions" => false } + exception = assert_raise(ActionDispatch::Http::Parameters::ParseError) do + post "/parse", params: json, headers: { "CONTENT_TYPE" => "application/json", "action_dispatch.show_exceptions" => false } + end assert_equal JSON::ParserError, exception.cause.class assert_equal exception.cause.message, exception.message ensure diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index 6ba52e37b6..c01065932a 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -364,18 +364,13 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end def test_pagemarks - tc = self draw do scope "pagemark", controller: "pagemarks", as: :pagemark do - tc.assert_deprecated do - get "new", path: "build" - end + get "build", action: "new", as: "new" post "create", as: "" put "update" get "remove", action: :destroy, as: :remove - tc.assert_deprecated do - get action: :show, as: :show - end + get "", action: :show, as: :show end end @@ -4684,22 +4679,25 @@ class TestUrlGenerationErrors < ActionDispatch::IntegrationTest include Routes.url_helpers - test "url helpers raise a helpful error message when generation fails" do + test "url helpers raise a 'missing keys' error for a nil param with optimized helpers" do url, missing = { action: "show", controller: "products", id: nil }, [:id] - message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" + message = "No route matches #{url.inspect}, missing required keys: #{missing.inspect}" - # Optimized url helper error = assert_raises(ActionController::UrlGenerationError) { product_path(nil) } assert_equal message, error.message + end + + test "url helpers raise a 'constraint failure' error for a nil param with non-optimized helpers" do + url, missing = { action: "show", controller: "products", id: nil }, [:id] + message = "No route matches #{url.inspect}, possible unmatched constraints: #{missing.inspect}" - # Non-optimized url helper error = assert_raises(ActionController::UrlGenerationError, message) { product_path(id: nil) } assert_equal message, error.message end - test "url helpers raise message with mixed parameters when generation fails " do + test "url helpers raise message with mixed parameters when generation fails" do url, missing = { action: "show", controller: "products", id: nil, "id"=>"url-tested" }, [:id] - message = "No route matches #{url.inspect} missing required keys: #{missing.inspect}" + message = "No route matches #{url.inspect}, possible unmatched constraints: #{missing.inspect}" # Optimized url helper error = assert_raises(ActionController::UrlGenerationError) { product_path(nil, "id"=>"url-tested") } diff --git a/actionpack/test/dispatch/show_exceptions_test.rb b/actionpack/test/dispatch/show_exceptions_test.rb index d8f673c212..3513534d72 100644 --- a/actionpack/test/dispatch/show_exceptions_test.rb +++ b/actionpack/test/dispatch/show_exceptions_test.rb @@ -11,7 +11,7 @@ class ShowExceptionsTest < ActionDispatch::IntegrationTest begin raise StandardError.new rescue - raise ActionDispatch::ParamsParser::ParseError + raise ActionDispatch::Http::Parameters::ParseError end when "/method_not_allowed" raise ActionController::MethodNotAllowed, "PUT" diff --git a/actionpack/test/dispatch/ssl_test.rb b/actionpack/test/dispatch/ssl_test.rb index 71b274bf1e..e29ffa750c 100644 --- a/actionpack/test/dispatch/ssl_test.rb +++ b/actionpack/test/dispatch/ssl_test.rb @@ -12,25 +12,16 @@ class SSLTest < ActionDispatch::IntegrationTest end class RedirectSSLTest < SSLTest - def assert_not_redirected(url, headers: {}, redirect: {}, deprecated_host: nil, - deprecated_port: nil) - - self.app = build_app ssl_options: { redirect: redirect, - host: deprecated_host, port: deprecated_port - } - + def assert_not_redirected(url, headers: {}, redirect: {}) + self.app = build_app ssl_options: { redirect: redirect } get url, headers: headers assert_response :ok end - def assert_redirected(redirect: {}, deprecated_host: nil, deprecated_port: nil, - from: "http://a/b?c=d", to: from.sub("http", "https")) - + def assert_redirected(redirect: {}, from: "http://a/b?c=d", to: from.sub("http", "https")) redirect = { status: 301, body: [] }.merge(redirect) - self.app = build_app ssl_options: { redirect: redirect, - host: deprecated_host, port: deprecated_port - } + self.app = build_app ssl_options: { redirect: redirect } get from assert_response redirect[:status] || 301 @@ -99,18 +90,6 @@ class RedirectSSLTest < SSLTest assert_redirected redirect: { host: "ssl:443" }, to: "https://ssl:443/b?c=d" end - test ":host is deprecated, moved within redirect: { host: … }" do - assert_deprecated do - assert_redirected deprecated_host: "foo", to: "https://foo/b?c=d" - end - end - - test ":port is deprecated, moved within redirect: { port: … }" do - assert_deprecated do - assert_redirected deprecated_port: 1, to: "https://a:1/b?c=d" - end - end - test "no redirect with redirect set to false" do assert_not_redirected "http://example.org", redirect: false end @@ -139,23 +118,19 @@ class StrictTransportSecurityTest < SSLTest end test "hsts: true enables default settings" do - assert_hsts EXPECTED, hsts: true + assert_hsts EXPECTED_WITH_SUBDOMAINS, hsts: true end test "hsts: false sets max-age to zero, clearing browser HSTS settings" do - assert_hsts "max-age=0", hsts: false + assert_hsts "max-age=0; includeSubDomains", hsts: false end test ":expires sets max-age" do - assert_deprecated do - assert_hsts "max-age=500", hsts: { expires: 500 } - end + assert_hsts "max-age=500; includeSubDomains", hsts: { expires: 500 } end test ":expires supports AS::Duration arguments" do - assert_deprecated do - assert_hsts "max-age=31557600", hsts: { expires: 1.year } - end + assert_hsts "max-age=31557600; includeSubDomains", hsts: { expires: 1.year } end test "include subdomains" do @@ -167,15 +142,11 @@ class StrictTransportSecurityTest < SSLTest end test "opt in to browser preload lists" do - assert_deprecated do - assert_hsts "#{EXPECTED}; preload", hsts: { preload: true } - end + assert_hsts "#{EXPECTED_WITH_SUBDOMAINS}; preload", hsts: { preload: true } end test "opt out of browser preload lists" do - assert_deprecated do - assert_hsts EXPECTED, hsts: { preload: false } - end + assert_hsts EXPECTED_WITH_SUBDOMAINS, hsts: { preload: false } end end diff --git a/actionpack/test/dispatch/static_test.rb b/actionpack/test/dispatch/static_test.rb index f72823a80e..aca70e180c 100644 --- a/actionpack/test/dispatch/static_test.rb +++ b/actionpack/test/dispatch/static_test.rb @@ -44,16 +44,6 @@ module StaticTests assert_equal "Hello, World!", get("/doorkeeper%00").body end - def test_sets_cache_control - app = assert_deprecated do - ActionDispatch::Static.new(DummyApp, @root, "public, max-age=60") - end - response = Rack::MockRequest.new(app).request("GET", "/index.html") - - assert_html "/index.html", response - assert_equal "public, max-age=60", response.headers["Cache-Control"] - end - def test_serves_static_index_at_root assert_html "/index.html", get("/index.html") assert_html "/index.html", get("/index") diff --git a/actionpack/test/dispatch/test_request_test.rb b/actionpack/test/dispatch/test_request_test.rb index 35af3076ba..b479af781d 100644 --- a/actionpack/test/dispatch/test_request_test.rb +++ b/actionpack/test/dispatch/test_request_test.rb @@ -88,6 +88,13 @@ class TestRequestTest < ActiveSupport::TestCase assert_equal "GoogleBot", req.user_agent end + test "request_method getter and setter" do + req = ActionDispatch::TestRequest.create + req.request_method # to reproduce bug caused by memoization + req.request_method = "POST" + assert_equal "POST", req.request_method + end + test "setter methods" do req = ActionDispatch::TestRequest.create({}) get = "GET" diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 2b99637f56..7b5916eb72 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -297,7 +297,7 @@ module ActionDispatch } request_parameters = primarty_parameters.merge(redirection_parameters).merge(missing_parameters) - message = "No route matches #{Hash[request_parameters.sort_by { |k,v|k.to_s }].inspect} missing required keys: #{[missing_key.to_sym].inspect}" + message = "No route matches #{Hash[request_parameters.sort_by { |k,v|k.to_s }].inspect}, missing required keys: #{[missing_key.to_sym].inspect}" error = assert_raises(ActionController::UrlGenerationError) do @formatter.generate( |