You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I run rails and perform a certain request, I get a response with:
Content-Type: application/json; charset=utf-8
However, when performing an Rspec controller test against that same controller, the response.content_type is just application/json which is not correct. Somehow, rspec is splitting off charset into response.charset which comes back as utf-8. This feels odd to do this since the actual header name where the charset is returned is Content-Type.
I'm not sure which code is doing this and obviously not breaking a bunch of existing tests is a concern, but this seems like a mismatch to me ...
Thoughts?
Thanks!
The text was updated successfully, but these errors were encountered:
The response object in controller specs is an instance of ActionController::TestResponse. However, content_type is inherited from ActionDispatch::Response. Per ActionDispatch::Response#content_type this is by design:
# Sets the HTTP response's content MIME type. For example, in the controller# you could write this:## response.content_type = "text/plain"## If a character set has been defined for this response (see charset=) then# the character set information will also be included in the content type# information.attr_reader:content_type# The charset of the response. HTML wants to know the encoding of the# content you're giving them, so we need to send that along.attr_accessor:charset
You are asking about the actual header value. You can get that from:
Hi,
When I run rails and perform a certain request, I get a response with:
However, when performing an Rspec controller test against that same controller, the
response.content_type
is justapplication/json
which is not correct. Somehow, rspec is splitting off charset intoresponse.charset
which comes back asutf-8
. This feels odd to do this since the actual header name where the charset is returned isContent-Type
.I'm not sure which code is doing this and obviously not breaking a bunch of existing tests is a concern, but this seems like a mismatch to me ...
Thoughts?
Thanks!
The text was updated successfully, but these errors were encountered: