API endpoint works with cURL but not test

I have an endpoint for registering new users. It works with cURL: curl -X POST -d email="usrrname@example.com" -d password="APassword!" http://localhost:3000/api/v1/registrations/.

But writing a test like this:

  user_params = { user: {
    email: Faker::Internet.email,
    password: Faker::Internet.password
  } }

  test 'Should register a new user' do
    post '/api/v1/registrations', params: user_params.to_json,
                                  headers: { 'Content-Type': 'application/json' }
    user = User.find_by(email: user_params[:user][:email])
    assert_not_nil user

This will fail and user will be nil: Expected nil to be truthy.

One thing I read is that with Rails you don’t have to specify the header type application/json in a request if it’s defined correctly in the routes or controller. This seems to be the case because I am not passing headers into the cURL request. I’ve tried removing the headers: but the outcome is the same.