Module: Jets::SpecHelpers::Controllers

Includes:
Router::Helpers
Included in:
Jets::SpecHelpers
Defined in:
lib/jets/spec_helpers/controllers.rb,
lib/jets/spec_helpers/controllers/params.rb,
lib/jets/spec_helpers/controllers/request.rb,
lib/jets/spec_helpers/controllers/response.rb

Defined Under Namespace

Classes: Params, Request, Response

Constant Summary

Constants included from Router::Helpers::CoreHelper

Router::Helpers::CoreHelper::CONTROLLER_DELEGATES

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Router::Helpers::NamedRoutesHelper

clear!

Methods included from Router::Helpers::CoreHelper

#polymorphic_path

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



5
6
7
# File 'lib/jets/spec_helpers/controllers.rb', line 5

def response
  @response
end

Instance Method Details

#http_call(method:, path:, **params) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jets/spec_helpers/controllers.rb', line 23

def http_call(method:, path:, **params)
  request.method = method.to_sym
  request.path = path
  request.headers.deep_merge!(params.delete(:headers) || {})

  request.params.query_params = params.delete(:query)

  if request.method == :get
    request.params.body_params = {}
    request.params.query_params ||= params.delete(:params)
    request.params.query_params ||= params
  else
    request.params.body_params = params.delete(:body)
    request.params.body_params ||= params.delete(:params)
    request.params.body_params ||= params
  end

  request.params.query_params ||= {}

  request.params.path_params = params

  @response = request.dispatch!
end

#requestObject

Note: caching it like this instead of within the initialize results in the headers not being cached See: community.rubyonjets.com/t/is-jets-spechelpers-controllers-request-being-cached/244/2



8
9
10
# File 'lib/jets/spec_helpers/controllers.rb', line 8

def request
  @request ||= Request.new(:get, '/', {}, Params.new)
end