It says there's an unexpected token in my params.
"ActionDispatch::Http::Parameters::ParseError: 765: unexpected token at 'conversation_identifier[participant_list][]=2&conversation_identifier[participant_list][]=1"
A version of the test with magic numbers for clarity:
let(:headers) do
{ 'HTTP_CURRENT_USER_ID' => 2,
'Content-Type' => 'application/json' }
end
let(:params) { { conversation_identifier: { participant_list: [1, 2] } }
it 'is getting testy' do
post resource_url, params: params, headers: headers
assert_equal 201, response.status
end
Now here's what's weird. It has no trouble parsing those params if I give it no headers.
Removing the 'Content-Type' => 'application/json'
solved the problem.
Finally remembered that ActionDispatch uses the headers to know how to parse the params. 'Content-Type' => 'application/json'
is a standard piece of boilerplate that's ok to throw around with GET
requests and query params but not with POST
when used this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With