I'm trying to achieve the following: create a POST json request within RSpec Controller test, passing it params. Here's my code
it 'returns access_token' do
post :login, email: 'bla', password: 'bla1', format: :json
end
What I get in controllers request.body.read is a string with params, but passed like this
email=bla&password=bla1
This is definitely not a JSON. But, if I make request using CURL
curl -d '{"email": "[email protected]" }' http://127.0.0.1:3000/users/login --header "Accept: application/json" --header "Content-Type: application/json"
I get my request.body.read as a correct json
"{\"email\": \"[email protected]\", \"password\": \"bla1\" }"
So how do I pass it this way from my rspec?
post "/models/#{@model.id}",
params: {
some_field: "1234",
},
as: :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