Skip to content

False positive on Rails/ResponseParsedBody #940

Closed
@jcoyne

Description

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions