Created
May 10, 2018 19:08
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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