Sha256: 5a57024c69d9dd63584f587862cdae51c5bda3b62e2b940994143c46250d3678

Contents?: true

Size: 1 KB

Versions: 18

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

# Methods for submitting test requests that are safe to use
# under both rails 4.x and 5.x
module SafeRequestHelpers
  def safe_get(endpoint, params = nil, headers = nil)
    safe_request(:get, endpoint, params, headers)
  end

  def safe_post(endpoint, params = nil, headers = nil)
    safe_request(:post, endpoint, params, headers)
  end

  def safe_put(endpoint, params = nil, headers = nil)
    safe_request(:put, endpoint, params, headers)
  end

  def safe_delete(endpoint, params = nil, headers = nil)
    safe_request(:delete, endpoint, params, headers)
  end

  def safe_request(method, endpoint, params, headers)
    if Rails.version.starts_with?('4')
      send(method, endpoint, params, headers)
    else
      options = { params: params }
      options[:headers] = headers if headers
      send(method, endpoint, **options)
    end
  end
end

RSpec.configure do |config|
  config.include SafeRequestHelpers, type: :controller
  config.include SafeRequestHelpers, type: :request
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
g5_authenticatable-1.1.4 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.4.rc.3 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.4.rc.2 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.4.rc.1 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.2 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.2.pre.1 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.2.rc.5 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.2.rc.4 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.2.rc.3 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.2.rc.2 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.2.rc.1 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.1 spec/support/safe_request_helpers.rb
g5_authenticatable-1.1.0 spec/support/safe_request_helpers.rb
g5_authenticatable-1.0.0 spec/support/safe_request_helpers.rb
g5_authenticatable-1.0.0.pre.4 spec/support/safe_request_helpers.rb
g5_authenticatable-1.0.0.pre.3 spec/support/safe_request_helpers.rb
g5_authenticatable-1.0.0.pre.2 spec/support/safe_request_helpers.rb
g5_authenticatable-1.0.0.pre.1 spec/support/safe_request_helpers.rb