We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
I'm seeing this error:
spec/controllers/spotlight/catalog_controller_spec.rb:308:16: C: [Correctable] Rails/ResponseParsedBody: Prefer response.parsed_body to JSON.parse(response.body). data = JSON.parse(response.body).with_indifferent_access ^^^^^^^^^^^^^^^^^^^^^^^^^
However I can not autocorrect this as parsed_body only works in the case that there is a parser found for the corresponding mime type. https://api.rubyonrails.org/classes/ActionDispatch/TestResponse.html#method-i-parsed_body
My response doesn't have one:
response.content_type "application/solr+json; charset=utf-8"
So this cop depends on the assumption that the request has a mime-type of application/json, which isn't going to be true for all cases.
application/json
The text was updated successfully, but these errors were encountered:
Autocorrect is marked unsafe for this very reason: https://docs.rubocop.org/rubocop-rails/cops_rails.html#safety-27
This cop’s autocorrection is unsafe because Content-Type may not be application/json
A potential workaround is to register a JSON encoder for your custom content-type for your test suite:
ActionDispatch::RequestEncoder.register_encoder :jsonapi, response_parser: ->(body) { JSON.parse(body) }
Sorry, something went wrong.
[Fix rubocop#940] Mark Rails/ResponseParsedBody as unsafe
Rails/ResponseParsedBody
8859d77
Fixes rubocop#940. This PR marks `Rails/ResponseParsedBody` as unsafe because I was misleading below: rubocop#863 (comment) It's actually unsafe.
Merge pull request #971 from koic/mark_rails_response_parsed_body_as_…
ce3abde
…unsafe [Fix #940] Mark `Rails/ResponseParsedBody` as unsafe
Successfully merging a pull request may close this issue.
I'm seeing this error:
However I can not autocorrect this as parsed_body only works in the case that there is a parser found for the corresponding mime type. https://api.rubyonrails.org/classes/ActionDispatch/TestResponse.html#method-i-parsed_body
My response doesn't have one:
So this cop depends on the assumption that the request has a mime-type of
application/json
, which isn't going to be true for all cases.The text was updated successfully, but these errors were encountered: