Allow content_type and format options in integration test requests

Hello!

I’m in the process of testing an api endpoint that handles image uploading and renders back json. It requires a Content-Type header of multipart/form-data and an Accept header of application/json. The as option allows both to be set at the same time by supplying the desired mime type, which is great, but if I want them to be different, I have to manually specify them in the headers hash.

Right now, my test request looks something like this:

post avatars_path, params: avatar_params, headers: { “Accept” => “multipart/form-data”, “Content-Type” => “application/json” }

``

I want it to look like this:

post api_account_v1_avatars_path, params: avatar_params, content_type: :multipart_form, format: :json

``

I would keep around as, since surely the most common use case is to have the two headers match, but I would add two new options, content_type and format (makes sense to match the name to what’s in ActionController::TestCase now).

Since content_type and format are more specific, they should override as if it’s also given. Another option is to throw an error if both are supplied.

Is this a common enough use case to warrant adding this feature to ActionDispatch::IntegrationTest?

Thanks in advance for the feedback!