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
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
16 17 18 |
# File 'lib/jets/spec_helpers/controllers.rb', line 16 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
16 17 18 |
# File 'lib/jets/spec_helpers/controllers.rb', line 16 def response @response end |
Instance Method Details
#http_call(method:, path:, **options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/jets/spec_helpers/controllers.rb', line 17 def http_call(method:, path:, **) headers = .delete(:headers) || {} md = path.match(/\?(.*)/) query_string = md ? md[1] : '' query = Rack::Utils.parse_nested_query(query_string) params = Params.new if method.to_sym == :get params.body_params = {} params.query_params ||= .delete(:params) || else params.body_params = .delete(:body) || .delete(:params) || end params.path_params = params.path_params params.query_params = query # Note: Do not cache the request object. Otherwise, it cannot be reused between specs. # See: https://community.rubyonjets.com/t/is-jets-spechelpers-controllers-request-being-cached/244/2 @request = Request.new(method, path, headers, params) @request.method = method.to_sym @request.path = path @request.headers.deep_merge!(headers) suppress_logging do @response = @request.dispatch! end end |