File: http_method_shim.rb

package info (click to toggle)
ruby-doorkeeper-openid-connect 1.7.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 648 kB
  • sloc: ruby: 2,915; makefile: 7; sh: 4
file content (36 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

# Rails 5 deprecates calling HTTP action methods with positional arguments
# in favor of keyword arguments. However, the keyword argument form is only
# supported in Rails 5+. Since we support back to 4, we need some sort of shim
# to avoid super noisy deprecations when running tests.
module RoutingHTTPMethodShim
  def get(path, **args)
    super(path, args[:params], args[:headers])
  end

  def post(path, **args)
    super(path, args[:params], args[:headers])
  end

  def put(path, **args)
    super(path, args[:params], args[:headers])
  end
end

module ControllerHTTPMethodShim
  def process(action, http_method = 'GET', **args)
    if (as = args.delete(:as))
      @request.headers['Content-Type'] = Mime[as].to_s
    end

    super(action, http_method, args[:params], args[:session], args[:flash])
  end
end

if ::Rails::VERSION::MAJOR < 5
  RSpec.configure do |config|
    config.include ControllerHTTPMethodShim, type: :controller
    config.include RoutingHTTPMethodShim, type: :request
  end
end