JSON Params being sent as empty string instead of nil in Specs
Asked Answered
S

0

6

Converting an app from Rails 4 to Rails 5. Everything is going well, though it seems this line is causing an issue. In Rails 4, it was:

get :show, token: user.token, email: user.email

With Rails 5, the syntax is:

get :show, params: { token: user.token, email: user.email }, format: :json

The problem in this case is that user.token is nil. Under Rails 4, the controller received the params as such:

{"token"=>nil, "email"=>"johndoe1@...", "action"=>"show"}

With Rails 5, now some tests are failing as the token is received as:

{"token"=>"", "email"=>"johndoe1@...", "action"=>"show"}

How can I get Rails 5 to respect it is null and not an empty string?

I don't know if this will affect gets outside of spec but I cannot find any solution to this. I tried as: :json, as well as format: :json, and even to_json, and nothing.

Thank you

Sheet answered 21/11, 2019 at 16:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.