提交 0cbb0be3 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #26746 from rails/deprecations

Remove all deprecations from Action Pack
......@@ -11,8 +11,8 @@ def test(html)
class AssertMultipartSelectMailer < ActionMailer::Base
def test(options)
mail subject: "Test e-mail", from: "test@test.host", to: "test <test@test.host>" do |format|
format.text { render text: options[:text] }
format.html { render text: options[:html] }
format.text { render plain: options[:text] }
format.html { render plain: options[:html] }
end
end
end
......
......@@ -18,7 +18,7 @@ def mail_with_i18n_subject(recipient)
class TestController < ActionController::Base
def send_mail
email = I18nTestMailer.mail_with_i18n_subject("test@localhost").deliver_now
render text: "Mail sent - Subject: #{email.subject}"
render plain: "Mail sent - Subject: #{email.subject}"
end
end
......
......@@ -62,8 +62,8 @@ def implicit_with_locale(hash = {})
def explicit_multipart(hash = {})
attachments["invoice.pdf"] = "This is test File content" if hash.delete(:attachments)
mail(hash) do |format|
format.text { render text: "TEXT Explicit Multipart" }
format.html { render text: "HTML Explicit Multipart" }
format.text { render plain: "TEXT Explicit Multipart" }
format.html { render plain: "HTML Explicit Multipart" }
end
end
......@@ -76,7 +76,7 @@ def explicit_multipart_templates(hash = {})
def explicit_multipart_with_any(hash = {})
mail(hash) do |format|
format.any(:text, :html) { render text: "Format with any!" }
format.any(:text, :html) { render plain: "Format with any!" }
end
end
......
* 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.
......
......@@ -54,25 +54,6 @@ def _normalize_callback_option(options, from, to) # :nodoc:
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 @@ def _insert_callbacks(callbacks, block = nil)
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 @@ def _insert_callbacks(callbacks, block = nil)
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
......
......@@ -55,7 +55,7 @@ def build_middleware(klass, args, block)
list = except
end
Middleware.new(get_class(klass), args, list, strategy, block)
Middleware.new(klass, args, list, strategy, block)
end
end
......
......@@ -3,20 +3,10 @@ class ActionControllerError < StandardError #:nodoc:
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:
......
......@@ -18,13 +18,7 @@ module Head
# 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
......
......@@ -104,14 +104,6 @@ def _compute_redirect_to_location(request, options) #:nodoc:
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
......
......@@ -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 @@ def _normalize_args(action=nil, options={}, &blk) #:nodoc:
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
......
......@@ -151,15 +151,6 @@ def initialize(parameters = {})
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 @@ def init_with(coder) # :nodoc:
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
......
......@@ -386,57 +386,42 @@ def determine_default_controller_class(name)
#
# 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,36 +452,14 @@ def xml_http_request(*args)
# 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 ||= {}
http_method = method.to_s.upcase
@html_document = nil
......@@ -517,12 +480,12 @@ def process(action, *args)
format ||= as
end
parameters = params.symbolize_keys
if format
parameters[:format] = format
end
parameters = parameters.symbolize_keys
generated_extras = @routes.generate_extras(parameters.merge(controller: controller_class_name, action: action.to_s))
generated_path = generated_path(generated_extras)
query_string_keys = query_parameter_names(generated_extras)
......@@ -641,38 +604,6 @@ def scrub_env!(env)
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
......
......@@ -54,7 +54,6 @@ class IllegalStateError < StandardError
autoload :ExceptionWrapper
autoload :Executor
autoload :Flash
autoload :ParamsParser
autoload :PublicExceptions
autoload :Reloader
autoload :RemoteIp
......
......@@ -45,32 +45,6 @@ def fetch(type)
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:
......
......@@ -12,6 +12,14 @@ module Parameters
}
}
# 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 @@ def parse_formatted_parameters(parsers)
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 @@ def params_parsers
end
end
end
module ParamsParser
ParseError = ActiveSupport::Deprecation::DeprecatedConstantProxy.new("ActionDispatch::ParamsParser::ParseError", "ActionDispatch::Http::Parameters::ParseError")
end
end
......@@ -357,7 +357,7 @@ def POST
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
......
......@@ -6,19 +6,19 @@ class ExceptionWrapper
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
......
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
......@@ -7,22 +7,12 @@
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
......
......@@ -45,35 +45,17 @@ class SSL
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
......
......@@ -88,7 +88,6 @@ def swap(target, *args, &block)
end
def delete(target)
target = get_class target
middlewares.delete_if { |m| m.klass == target }
end
......@@ -103,31 +102,13 @@ def build(app = Proc.new)
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
......@@ -106,14 +106,7 @@ def gzip_file_path(path)
# 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
......
......@@ -1558,11 +1558,7 @@ def match(path, *rest, &block)
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 @@ def map_match(paths, options)
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)
......
......@@ -38,72 +38,40 @@ module RequestHelpers
#
# 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 @@ def follow_redirect!
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 @@ def _mock_session
@_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)
......
......@@ -264,53 +264,5 @@ class TestCallbacksWithArgs < ActiveSupport::TestCase
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
......@@ -23,10 +23,6 @@ def two
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 @@ def test_render_plain
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
......@@ -2,7 +2,7 @@
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 @@ def test_last_action_in_multiple_before_action_chain_halts
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
......
......@@ -31,95 +31,6 @@ def test_follow_redirect_raises_when_no_redirect
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,26 +46,7 @@ def test_get_with_env_and_headers
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)
......@@ -168,15 +60,6 @@ def test_patch
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,25 +67,7 @@ def test_put
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)
......@@ -216,15 +81,6 @@ def test_head
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 @@ def test_xml_http_request_get
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 @@ def test_xml_http_request_post
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 @@ def test_xml_http_request_patch
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 @@ def test_xml_http_request_put
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 @@ def test_xml_http_request_delete
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
......@@ -585,18 +355,6 @@ def test_xml_http_request_get
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
......
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
......@@ -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)
......
......@@ -56,10 +56,6 @@ def relative_url_redirect_with_status_hash
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 @@ def redirect_to_url_with_network_path_reference
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 @@ def test_relative_url_redirect_with_status_hash
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 @@ def test_redirect_to_url_with_network_path_reference
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
......
......@@ -160,10 +160,6 @@ def conditional_hello_with_cache_control_headers
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 @@ def handle_last_modified_and_etags
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 @@ def test_expires_now_with_cache_control_headers
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 @@ def test_head_created
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?
......
......@@ -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
......
......@@ -229,14 +229,6 @@ def test_body_stream
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 @@ def test_document_body_with_post
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 @@ def test_process_without_flash
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 @@ def test_process_with_flash
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 @@ def test_process_with_session
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 @@ def test_process_with_session_kwarg
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 @@ def test_process_merges_session_arg
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 @@ def test_process_with_symbol_method
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 @@ def test_process_with_request_uri_with_params
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 @@ def test_assert_routing_with_glob
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 @@ def test_params_passing_path_parameter_is_string_when_not_html_request
)
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: {
......@@ -683,11 +594,6 @@ def test_id_converted_to_string
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
......@@ -742,12 +648,6 @@ def test_header_properly_reset_after_remote_http_request
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
......@@ -763,23 +663,6 @@ def test_xhr_with_session
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]
......@@ -979,15 +862,6 @@ def test_fixture_file_upload_ignores_nil_fixture_path
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}"
......
......@@ -18,14 +18,6 @@ def setup
@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 @@ def test_delete_works
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 @@ def test_delete_works
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 @@ def test_delete_works
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
......
......@@ -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")
......
......@@ -75,7 +75,9 @@ def teardown
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
......
......@@ -364,18 +364,13 @@ def test_bookmarks
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
......
......@@ -11,7 +11,7 @@ def call(env)
begin
raise StandardError.new
rescue
raise ActionDispatch::ParamsParser::ParseError
raise ActionDispatch::Http::Parameters::ParseError
end
when "/method_not_allowed"
raise ActionController::MethodNotAllowed, "PUT"
......
......@@ -12,25 +12,16 @@ def build_app(headers: {}, ssl_options: {})
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 @@ def assert_post_redirected(redirect: {}, from: "http://a/b?c=d",
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 @@ def assert_hsts(expected, url: "https://example.org", hsts: { subdomains: true }
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 @@ def assert_hsts(expected, url: "https://example.org", hsts: { subdomains: true }
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
......
......@@ -44,16 +44,6 @@ def test_handles_urls_with_null_byte
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")
......
......@@ -426,7 +426,7 @@ def _default_layout(formats, require_layout = false)
end
def _include_layout?(options)
(options.keys & [:body, :text, :plain, :html, :inline, :partial]).empty? || options.key?(:layout)
(options.keys & [:body, :plain, :html, :inline, :partial]).empty? || options.key?(:layout)
end
end
end
......@@ -22,8 +22,6 @@ def determine_template(options)
if options.key?(:body)
Template::Text.new(options[:body])
elsif options.key?(:text)
Template::Text.new(options[:text], formats.first)
elsif options.key?(:plain)
Template::Text.new(options[:plain])
elsif options.key?(:html)
......@@ -40,7 +38,7 @@ def determine_template(options)
find_template(options[:template], options[:prefixes], false, keys, @details)
end
else
raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file, :plain, :html, :text or :body option."
raise ArgumentError, "You invoked render but did not give any of :partial, :template, :inline, :file, :plain, :html or :body option."
end
end
......
......@@ -55,7 +55,7 @@ def test_render_file_template
def test_render_text_template
Rails.stub(:root, File.expand_path(FIXTURE_LOAD_PATH)) do
@view.render(text: "TEXT")
@view.render(plain: "TEXT")
wait
assert_equal 2, @logger.logged(:info).size
......
......@@ -285,7 +285,7 @@ def render_from_helper
class AssertionsTest < ActionView::TestCase
def render_from_helper
form_tag("/foo") do
safe_concat render(text: "<ul><li>foo</li></ul>")
safe_concat render(plain: "<ul><li>foo</li></ul>")
end
end
helper_method :render_from_helper
......
......@@ -462,23 +462,23 @@ encrypted cookies salt value. Defaults to `'signed encrypted cookie'`.
```ruby
config.action_dispatch.rescue_responses = {
'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,
'ActiveRecord::RecordNotFound' => :not_found,
'ActiveRecord::StaleObjectError' => :conflict,
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
'ActiveRecord::RecordNotSaved' => :unprocessable_entity
'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,
'ActiveRecord::RecordNotFound' => :not_found,
'ActiveRecord::StaleObjectError' => :conflict,
'ActiveRecord::RecordInvalid' => :unprocessable_entity,
'ActiveRecord::RecordNotSaved' => :unprocessable_entity
}
```
......
......@@ -375,7 +375,7 @@ class User < ActiveRecord::Base; raise 'should not be reached'; end
class ::OmgController < ActionController::Base
def index
flash[:cool_story] = true
render text: "ok"
render plain: "ok"
end
end
......
......@@ -398,7 +398,7 @@ def assert_utf8
class ::OmgController < ActionController::Base
def index
cookies.signed[:some_key] = "some_value"
render text: cookies[:some_key]
render plain: cookies[:some_key]
end
end
......@@ -704,7 +704,7 @@ def show
end
def update
render text: "update"
render plain: "update"
end
private
......@@ -978,7 +978,7 @@ def index
class ::OmgController < ActionController::Base
def index
render text: env["action_dispatch.show_exceptions"]
render plain: env["action_dispatch.show_exceptions"]
end
end
......@@ -1008,7 +1008,7 @@ class ApplicationController < ActionController::Base
app_file "app/controllers/posts_controller.rb", <<-RUBY
class PostsController < ApplicationController
def create
render text: params[:post].inspect
render plain: params[:post].inspect
end
end
RUBY
......@@ -1029,7 +1029,7 @@ def create
app_file "app/controllers/posts_controller.rb", <<-RUBY
class PostsController < ActionController::Base
def create
render text: params[:post].permitted? ? "permitted" : "forbidden"
render plain: params[:post].permitted? ? "permitted" : "forbidden"
end
end
RUBY
......@@ -1051,7 +1051,7 @@ def create
app_file "app/controllers/posts_controller.rb", <<-RUBY
class PostsController < ActionController::Base
def create
render text: params.require(:post).permit(:name)
render plain: params.require(:post).permit(:name)
end
end
RUBY
......@@ -1090,7 +1090,7 @@ def create
app_file "app/controllers/posts_controller.rb", <<-RUBY
class PostsController < ActionController::Base
def create
render text: params.permit(post: [:title])
render plain: params.permit(post: [:title])
end
end
RUBY
......@@ -1137,8 +1137,8 @@ def create
class ::OmgController < ActionController::Base
def index
respond_to do |format|
format.html { render text: "HTML" }
format.xml { render text: "XML" }
format.html { render plain: "HTML" }
format.xml { render plain: "XML" }
end
end
end
......
......@@ -19,7 +19,7 @@ def simple_controller
class ExpiresController < ApplicationController
def expires_header
expires_in 10, public: !params[:private]
render text: SecureRandom.hex(16)
render plain: SecureRandom.hex(16)
end
def expires_etag
......@@ -32,12 +32,12 @@ def expires_last_modified
end
def keeps_if_modified_since
render :text => request.headers['If-Modified-Since']
render plain: request.headers['If-Modified-Since']
end
private
def render_conditionally(headers)
if stale?(headers.merge(public: !params[:private]))
render text: SecureRandom.hex(16)
render plain: SecureRandom.hex(16)
end
end
end
......
......@@ -70,7 +70,7 @@ def write_session
end
def read_session
render text: session[:foo].inspect
render plain: session[:foo].inspect
end
end
RUBY
......@@ -111,7 +111,7 @@ def write_cookie
end
def read_cookie
render text: cookies[:foo].inspect
render plain: cookies[:foo].inspect
end
end
RUBY
......@@ -149,15 +149,15 @@ def write_session
end
def read_session
render text: session[:foo]
render plain: session[:foo]
end
def read_encrypted_cookie
render text: cookies.encrypted[:_myapp_session]['foo']
render plain: cookies.encrypted[:_myapp_session]['foo']
end
def read_raw_cookie
render text: cookies[:_myapp_session]
render plain: cookies[:_myapp_session]
end
end
RUBY
......@@ -194,15 +194,15 @@ def write_session
end
def read_session
render text: session[:foo]
render plain: session[:foo]
end
def read_encrypted_cookie
render text: cookies.encrypted[:_myapp_session]['foo']
render plain: cookies.encrypted[:_myapp_session]['foo']
end
def read_raw_cookie
render text: cookies[:_myapp_session]
render plain: cookies[:_myapp_session]
end
end
RUBY
......@@ -249,15 +249,15 @@ def write_session
end
def read_session
render text: session[:foo]
render plain: session[:foo]
end
def read_encrypted_cookie
render text: cookies.encrypted[:_myapp_session]['foo']
render plain: cookies.encrypted[:_myapp_session]['foo']
end
def read_raw_cookie
render text: cookies[:_myapp_session]
render plain: cookies[:_myapp_session]
end
end
RUBY
......@@ -308,15 +308,15 @@ def write_session
end
def read_session
render text: session[:foo]
render plain: session[:foo]
end
def read_signed_cookie
render text: cookies.signed[:_myapp_session]['foo']
render plain: cookies.signed[:_myapp_session]['foo']
end
def read_raw_cookie
render text: cookies[:_myapp_session]
render plain: cookies[:_myapp_session]
end
end
RUBY
......
......@@ -100,10 +100,10 @@ def app
test "ActionDispatch::SSL is configured with options when given" do
add_to_config "config.force_ssl = true"
add_to_config "config.ssl_options = { host: 'example.com' }"
add_to_config "config.ssl_options = { redirect: { host: 'example.com' } }"
boot!
assert_equal [{ host: "example.com" }], Rails.application.middleware.first.args
assert_equal [{ redirect: { host: "example.com" } }], Rails.application.middleware.first.args
end
test "removing Active Record omits its middleware" do
......@@ -227,9 +227,9 @@ def app
class ::OmgController < ActionController::Base
def index
if params[:nothing]
render text: ""
render plain: ""
else
render text: "OMG"
render plain: "OMG"
end
end
end
......@@ -239,7 +239,7 @@ def index
get "/"
assert_equal 200, last_response.status
assert_equal "OMG", last_response.body
assert_equal "text/html; charset=utf-8", last_response.headers["Content-Type"]
assert_equal "text/plain; charset=utf-8", last_response.headers["Content-Type"]
assert_equal "max-age=0, private, must-revalidate", last_response.headers["Cache-Control"]
assert_equal etag, last_response.headers["Etag"]
......@@ -253,7 +253,7 @@ def index
get "/?nothing=true"
assert_equal 200, last_response.status
assert_equal "", last_response.body
assert_equal "text/html; charset=utf-8", last_response.headers["Content-Type"]
assert_equal "text/plain; charset=utf-8", last_response.headers["Content-Type"]
assert_equal "no-cache", last_response.headers["Cache-Control"]
assert_equal nil, last_response.headers["Etag"]
end
......
......@@ -65,7 +65,7 @@ def teardown
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render text: "foo"
render plain: "foo"
end
end
RUBY
......@@ -156,7 +156,7 @@ def foo_or_bar?
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render text: my_blog_path
render plain: my_blog_path
end
end
RUBY
......@@ -176,7 +176,7 @@ def index
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render text: "foo"
render plain: "foo"
end
end
RUBY
......@@ -184,7 +184,7 @@ def index
controller :bar, <<-RUBY
class BarController < ActionController::Base
def index
render text: "bar"
render plain: "bar"
end
end
RUBY
......@@ -206,7 +206,7 @@ def index
controller "foo", <<-RUBY
class FooController < ApplicationController
def index
render text: "foo"
render plain: "foo"
end
end
RUBY
......@@ -215,7 +215,7 @@ def index
module Admin
class FooController < ApplicationController
def index
render text: "admin::foo"
render plain: "admin::foo"
end
end
end
......@@ -268,11 +268,11 @@ def index
controller :foo, <<-RUBY
class FooController < ApplicationController
def bar
render text: "bar"
render plain: "bar"
end
def baz
render text: "baz"
render plain: "baz"
end
end
RUBY
......@@ -332,7 +332,7 @@ def test_root_path
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render :text => "foo"
render plain: "foo"
end
end
RUBY
......@@ -356,7 +356,7 @@ def index
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render text: "foo"
render plain: "foo"
end
end
RUBY
......@@ -364,7 +364,7 @@ def index
controller :bar, <<-RUBY
class BarController < ApplicationController
def index
render text: "bar"
render plain: "bar"
end
end
RUBY
......@@ -427,7 +427,7 @@ def index
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render text: "foo"
render plain: "foo"
end
end
RUBY
......@@ -435,7 +435,7 @@ def index
controller :bar, <<-RUBY
class BarController < ApplicationController
def index
render text: "bar"
render plain: "bar"
end
end
RUBY
......@@ -482,7 +482,7 @@ def index
controller "yazilar", <<-RUBY
class YazilarController < ApplicationController
def index
render text: 'yazilar#index'
render plain: 'yazilar#index'
end
end
RUBY
......
......@@ -27,7 +27,7 @@ class ::ApplicationController < ActionController::Base
class ::OmgController < ::ApplicationController
def index
render text: omg_path
render plain: omg_path
end
end
......
......@@ -187,7 +187,7 @@ def simple_controller
controller :foo, <<-RUBY
class FooController < ApplicationController
def index
render text: "foo"
render plain: "foo"
end
end
RUBY
......
......@@ -327,7 +327,7 @@ def self.call(env)
controller "foo", <<-RUBY
class FooController < ActionController::Base
def index
render :text => "foo"
render plain: "foo"
end
end
RUBY
......@@ -341,7 +341,7 @@ def index
@plugin.write "app/controllers/bar_controller.rb", <<-RUBY
class BarController < ActionController::Base
def index
render :text => "bar"
render plain: "bar"
end
end
RUBY
......@@ -436,7 +436,7 @@ def index
@plugin.write "app/controllers/admin/foo/bar_controller.rb", <<-RUBY
class Admin::Foo::BarController < ApplicationController
def index
render text: "Rendered from namespace"
render plain: "Rendered from namespace"
end
end
RUBY
......@@ -536,7 +536,7 @@ class Engine < ::Rails::Engine
controller "foo", <<-RUBY
class FooController < ActionController::Base
def index
render text: params[:username]
render plain: params[:username]
end
end
RUBY
......@@ -700,7 +700,7 @@ def index
end
def show
render text: foo_path
render plain: foo_path
end
def from_app
......@@ -712,7 +712,7 @@ def routes_helpers_in_view
end
def polymorphic_path_without_namespace
render text: polymorphic_path(Post.new)
render plain: polymorphic_path(Post.new)
end
end
RUBY
......@@ -835,7 +835,7 @@ class Engine < ::Rails::Engine
@plugin.write "app/controllers/bukkits/awesome/foo_controller.rb", <<-RUBY
class Bukkits::Awesome::FooController < ActionController::Base
def index
render :text => "ok"
render plain: "ok"
end
end
RUBY
......@@ -1220,7 +1220,7 @@ def index
fullpath: \#{request.fullpath}
path: \#{request.path}
TEXT
render text: text
render plain: text
end
end
end
......@@ -1257,7 +1257,7 @@ class Engine < ::Rails::Engine
app_file "app/controllers/bar_controller.rb", <<-RUBY
class BarController < ApplicationController
def index
render text: bukkits.bukkit_path
render plain: bukkits.bukkit_path
end
end
RUBY
......@@ -1278,7 +1278,7 @@ def index
@plugin.write "app/controllers/bukkits/bukkit_controller.rb", <<-RUBY
class Bukkits::BukkitController < ActionController::Base
def index
render text: main_app.bar_path
render plain: main_app.bar_path
end
end
RUBY
......@@ -1306,7 +1306,7 @@ class Engine < ::Rails::Engine
app_file "app/controllers/bar_controller.rb", <<-RUBY
class BarController < ApplicationController
def index
render text: bukkits.bukkit_path
render plain: bukkits.bukkit_path
end
end
RUBY
......@@ -1327,7 +1327,7 @@ def index
@plugin.write "app/controllers/bukkits/bukkit_controller.rb", <<-RUBY
class Bukkits::BukkitController < ActionController::Base
def index
render text: main_app.bar_path
render plain: main_app.bar_path
end
end
RUBY
......
......@@ -50,7 +50,7 @@ class Engine < ::Rails::Engine
@simple_plugin.write "app/controllers/weblogs_controller.rb", <<-RUBY
class WeblogsController < ActionController::Base
def index
render text: request.url
render plain: request.url
end
end
RUBY
......@@ -74,7 +74,7 @@ class Engine < ::Rails::Engine
module Metrics
class GeneratingController < ActionController::Base
def generate_blog_route
render text: blog.post_path(1)
render plain: blog.post_path(1)
end
def generate_blog_route_in_view
......@@ -122,14 +122,14 @@ class Engine < ::Rails::Engine
module Blog
class PostsController < ActionController::Base
def index
render text: blog.post_path(1)
render plain: blog.post_path(1)
end
def generate_application_route
path = main_app.url_for(controller: "/main",
action: "index",
only_path: true)
render text: path
render plain: path
end
def application_route_in_view
......@@ -137,7 +137,7 @@ def application_route_in_view
end
def engine_polymorphic_path
render text: polymorphic_path(Post.new)
render plain: polymorphic_path(Post.new)
end
def engine_asset_path
......@@ -150,7 +150,7 @@ def engine_asset_path
app_file "app/controllers/application_generating_controller.rb", <<-RUBY
class ApplicationGeneratingController < ActionController::Base
def engine_route
render text: blog.posts_path
render plain: blog.posts_path
end
def engine_route_in_view
......@@ -158,7 +158,7 @@ def engine_route_in_view
end
def weblog_engine_route
render text: weblog.weblogs_path
render plain: weblog.weblogs_path
end
def weblog_engine_route_in_view
......@@ -166,15 +166,15 @@ def weblog_engine_route_in_view
end
def url_for_engine_route
render text: blog.url_for(controller: "blog/posts", action: "index", user: "john", only_path: true)
render plain: blog.url_for(controller: "blog/posts", action: "index", user: "john", only_path: true)
end
def polymorphic_route
render text: polymorphic_url([blog, Blog::Post.new])
render plain: polymorphic_url([blog, Blog::Post.new])
end
def application_polymorphic_path
render text: polymorphic_path(Blog::Post.new)
render plain: polymorphic_path(Blog::Post.new)
end
end
RUBY
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册