-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow setting of request CONTENT-TYPE with as: in controller tests #26212
Allow setting of request CONTENT-TYPE with as: in controller tests #26212
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
Could you add a test for this feature in https://github.com/rails/rails/blob/master/actionpack/test/controller/test_case_test.rb? It will be something like https://github.com/rails/rails/blob/master/actionpack/test/controller/test_case_test.rb#L640-L647, but we will need to assert the Content type and if the parameters where parsed using the content type provided. |
Added a test case for this 👍 |
could you squash your commits and a CHANGELOG entry on top of https://github.com/rails/rails/blob/master/actionpack/CHANGELOG.md? |
Oh, forgot about the documentation. Could you update the |
Does this do more than making the option shorter to type? 😕 I'm slightly concerned that it creates a parallel in the APIs that isn't supported by the implementations. cc @kaspth |
Yes, it actually set the content type. We already have |
Documentation & testing
73b6f59
to
3db57bd
Compare
Documentation & changelog updated as well! |
@rafaelfranca thanks for the update and continuing to see this through! Great work @evmunro! This will hopefully make it easier for those upgrading to Rails 5 from 4.2 since I was spending a lot of time tackling this issue. Thanks ❤️ |
To give context why this change is needed: Since c546a2b, To fix this in Rails 5.0.0 you have to set the request's content type by hand. While this is an acceptable solution it is too cumbersome. |
…or-controller-test Allow setting of request CONTENT-TYPE with as: in controller tests
Backported in 09d313a |
@evmunro, @rafaelfranca awesome thanks! ❤️ |
Neat! As long as we also make It depends on us having a content type at the time we create the response class:
|
Summary
Adds the option for specifications such as
as: :json
to set the request header, forget, post,...
etc methods in controller tests.For example:
post :action, params: { ... }, as: :json
sets theCONTENT-TYPE
of the request toapplication/json
.r? @rafaelfranca