Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rspec Controller tests, passing JSON params

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?

like image 378
Xentatt Avatar asked Mar 12 '15 17:03

Xentatt


1 Answers

post "/models/#{@model.id}",
        params: {
            some_field: "1234",
        },
        as: :json
like image 78
thelastinuit Avatar answered Nov 16 '22 23:11

thelastinuit