-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test keyword args in requests for Rails 5; fallback for earlier versions
kwargs: params,session,flash,method,body Fix Rails 5 DEPRECATION WARNING
- Loading branch information
Showing
4 changed files
with
44 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Rails5Shims | ||
module ControllerTests | ||
# https://github.com/rails/rails/blob/b217354/actionpack/lib/action_controller/test_case.rb | ||
REQUEST_KWARGS = %i(params session flash method body xhr) | ||
|
||
# Fold kwargs from test request into args | ||
# Band-aid for DEPRECATION WARNING | ||
def get(path, *args) | ||
hash = args && args[0] | ||
if hash.respond_to?(:key) | ||
Rails5Shims::ControllerTests::REQUEST_KWARGS.each do |kwarg| | ||
next unless hash.key?(kwarg) | ||
hash.merge! hash.delete(kwarg) | ||
end | ||
end | ||
super | ||
end | ||
|
||
# Uncomment for debugging where the kwargs warnings come from | ||
# def non_kwarg_request_warning | ||
# super.tap do | ||
# STDOUT.puts caller[2..3] | ||
# end | ||
# end | ||
end | ||
end | ||
if Rails::VERSION::MAJOR < 5 | ||
ActionController::TestCase.send :include, Rails5Shims::ControllerTests | ||
end |
This file contains 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
This file contains 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