Looks like a bug in RSpec but maybe I'm missing something.
I have a request spec where I post a JSON that contains an array of hashes:
spec/requests/dummy_request_spec.rb:
post "http://my.server.com/some/route", {
format: :json,
data: [
{
details: {
param1: 1
},
},
{
details: {
param2: 1
}
}
]
}
For some odd reason, RSpec merges the hashes into one element and then sends them to server. print out of params received in controller:
data: [
{
details: {
param1: 1,
param2: 2
},
},
]
versions: rspec-2.13.0 rails-3.2.10
Very strange!!
Thanks
Got it! array of hashes is not supported for form-data
RSpec by default posts it as form-data. Solution:
post '...', {...}.to_json, {'CONTENT_TYPE' => "application/json", 'ACCEPT' => 'application/json'}
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