Boolean attribute becomes a string when doing_request
Hi,
In the following do_request, terms becomes a string "true" instead of staying a boolean true.
it "creates new user" do
user = build(:user)
do_request(
username: user.username,
email: user.email,
password: user.password,
password_confirmation: user.password,
terms: true)
expect(status).to eq(200)
@data = JSON.parse(response_body)
expect(@data["status"]).to include("success")
expect(@data["data"]["email"]).to include(user.email)
end
which means that just for my tests, I have to do the following in my model:
validates_acceptance_of :terms, allow_nil: false, on: [:create], accept: [true, "true"]
^
Do you know if this expected or a bug? Thank you
I think this is a bug. You should be able to pass through as: :json but it doesn't seem to work.
I am getting the same issue with integers turning into strings.
See: https://github.com/rspec/rspec-rails/issues/610
This just needs better set up to work as you are expecting it to. do_request will send as a post body which will convert everything to strings. If you're sending JSON data you need to alter the raw_post variable via a let(:raw_post) { ... }.