jets icon indicating copy to clipboard operation
jets copied to clipboard

Fix controller testing in jets 5 - handling of params and query

Open webandtech opened this issue 1 year ago • 0 comments

This is a 🐞 bug fix.

  • [ ] I've added tests (if it's a bug, feature or enhancement)
  • [ ] I've adjusted the documentation (if it's a feature or enhancement)
  • [X] The test suite passes (run bundle exec rspec to verify this)

Summary

Jets v5 controller testing is broken for get requests. If you attempt to pass params or a query, the params are not passed to the request correctly. Furthermore, adding a query i.e. my/path?foo=bar will not match with the route my/path.

This PR fixes the above bugs by extracting the query, merging it with any params passed in the options, removing the query from the path, and then passing these into the request correctly.

How to Test

In your jets app, create a controller expecting a GET request with specific params which responds successfully only if specific params are present. Write a spec for this controller action, passing in params i.e. get '/my/path', params: { required_param: 'foo'}

Prior to this PR, the params passed in will not be available to the controller action. This PR fixes the problem.

Version Changes

patch

webandtech avatar Feb 12 '24 14:02 webandtech