Search code examples
ruby-on-railsarraysparametersruby-on-rails-5.1

Rails 5.1 minitest flattens array of arrays in params


After upgrading from Rails 4.2 to 5.1 it seems that only for the tests, when I provide something like:

post :create, params: {
  model: {
    prices: [[2000, "EUR"], [2113.56, "USD"]],
    estimates: [[50, 2500, "EUR"], [505, 2600, "USD"]]
  }
}

It is then parsed within the params of the controller as:

prices: [["2000"], ["EUR"], ["2113.56"], ["USD"]]
estimates: [["50"], ["2500"], ["EUR"], ["505"], ["2600"], ["USD"]]

Fortunately, actual calls to the controller are parsed correctly. I need the tests fixed though obviously, so any help would be really appreciated!


Solution

  • Found the answer after so much time..

    We thought that by having only: @request.headers['Accept'] = 'application/json' in setup was ok.

    But we also had to include: @request.headers['Content-Type'] = 'application/json' in order for the params to be parsed correctly!