Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save GPrimola/2a7b2b3d29614cdfb9d4fe115b4c3852 to your computer and use it in GitHub Desktop.

Select an option

Save GPrimola/2a7b2b3d29614cdfb9d4fe115b4c3852 to your computer and use it in GitHub Desktop.
Monkey patch adapter to stop warning messages of deprecated style when using rails-controller-testing gem
module Rails::Controller::Testing::Integration
%w(
get post patch put head delete xml_http_request
xhr get_via_redirect post_via_redirect
).each do |method|
define_method(method) do |*args|
if old_fashion?(args)
action = args.first
params = args[1]
args = [action, { params: params }]
end
super(*args)
end
end
def old_fashion?(args)
args.size > 1 &&
[String, Symbol].include?(args.first.class) &&
args.select do |arg|
arg.is_a?(Hash) &&
!arg.has_key?(:params) && !arg.has_key?(:headers)
end.any?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment