Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat
as: :html
tests request params as :url_encoded_form
Closes [#50345][] First, handle the exception mentioned in [#50345][]: ``` BugTest#test_params_with_htm_content_type: NoMethodError: undefined method `to_html' for {:name=>"Muad'Dib"}:Hash .../actionpack/lib/action_dispatch/testing/request_encoder.rb:39:in `encode_params' .../actionpack/lib/action_dispatch/testing/integration.rb:251:in `process' ``` Calls with `as: :html` result in a `NoMethodError` because `Hash#to_html` does not exist. Passing `as: :html` implies that the request parameters will come from a `POST` body encoded as `text/html`. That isn't entirely true -- browsers will encode `POST` parameters as with the `Content-Type:` header set to either [application/x-www-form-urlencoded][] or [multipart/form-data][]. This commit skips setting the `CONTENT_TYPE` Rack header when processed with `as: :html`. To account for that, extend the `RequestEncoder` constructor to accept a `content_type `argument to use when provided. When omitted, continue to fall back to the provided MIME type. Extend the default `:html` encoder configuration to default to submitting with `Content-Type: x-www-form-urlencoded`. [#50345]: #50345 [application/x-www-form-urlencoded]: https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data#the_post_method [multipart/form-data]: https://developer.mozilla.org/en-US/docs/Learn/Forms/Sending_and_retrieving_form_data#the_enctype_attribute
- Loading branch information