Skip to content

Commit

Permalink
Merge pull request #1435 from bf4/fix_rails_warnings
Browse files Browse the repository at this point in the history
Fix Rails 5 warnings (uses Rails5Shim)
  • Loading branch information
remear committed Mar 15, 2016
2 parents 9e99235 + d65a72e commit db87f8d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/action_controller/json_api/deserialization_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_deserialization
}
}

post :render_parsed_payload, hash
post :render_parsed_payload, params: hash

response = JSON.parse(@response.body)
expected = {
Expand Down
32 changes: 25 additions & 7 deletions test/support/rails5_shims.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,35 @@ module ControllerTests
# https://github.com/rails/rails/blob/b217354/actionpack/lib/action_controller/test_case.rb
REQUEST_KWARGS = [:params, :session, :flash, :method, :body, :xhr].freeze

def get(path, *args)
fold_kwargs!(args)
super
end

def post(path, *args)
fold_kwargs!(args)
super
end

def patch(path, *args)
fold_kwargs!(args)
super
end

def put(path, *args)
fold_kwargs!(args)
super
end

# Fold kwargs from test request into args
# Band-aid for DEPRECATION WARNING
def get(path, *args)
def fold_kwargs!(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
return unless hash.respond_to?(:key)
Rails5Shims::ControllerTests::REQUEST_KWARGS.each do |kwarg|
next unless hash.key?(kwarg)
hash.merge! hash.delete(kwarg)
end
super
end

# Uncomment for debugging where the kwargs warnings come from
Expand Down

0 comments on commit db87f8d

Please sign in to comment.