Skip to content

Commit

Permalink
Clarify xhr deprecation message. Don't support kwargs.
Browse files Browse the repository at this point in the history
Prevent hitting integration tests users with two deprecation warnings by
clarifying how they should upgrade to the request helpers `get` and friends.

It's hard to imagine people having `xhr` calls that use keywords, why not
follow the xhr deprecation message? Why instead insert a middle layer of
migration?

They have to switch to something else anyway, so just show how that looks
and nudge them a bit more.

The code was originally added in #18323,
but then wasn't touched when deprecating xhr in
#18771.
  • Loading branch information
kaspth committed Aug 13, 2016
1 parent f8ee669 commit 258f4e7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/test_case.rb
Expand Up @@ -415,8 +415,8 @@ def head(action, *args)

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`
`xhr` and `xml_http_request` are deprecated and will be removed in Rails 5.1.
Switch to e.g. `post :create, params: { comment: { body: 'Honey bunny' } }, xhr: true`.
MSG

@request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
Expand Down
22 changes: 5 additions & 17 deletions actionpack/lib/action_dispatch/testing/integration.rb
Expand Up @@ -81,26 +81,14 @@ def head(path, *args)
#
# 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

# xhr :get, '/feed', since: 201501011400
def xml_http_request(request_method, path, parameters = nil, headers_or_env = nil)
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`.
`xhr` and `xml_http_request` are deprecated and will be removed in Rails 5.1.
Switch to e.g. `post comments_path, params: { comment: { body: 'Honey bunny' } }, xhr: true`.
MSG

process(request_method, path, params: params, headers: headers, xhr: true)
process(request_method, path, params: parameters, headers: headers_or_env, xhr: true)
end
alias xhr :xml_http_request

Expand Down

0 comments on commit 258f4e7

Please sign in to comment.