Providing JSON data no longer works in request specs with Rails 7.1
mockdeep opened this issue · 6 comments
What Ruby, Rails and RSpec versions are you using?
Ruby version: 3.2.2
Rails version: 7.1.0
RSpec version: 3.1.2
Observed behaviour
When upgrading to Rails 7.1, request specs no longer allow us to pass string json with the params:
key. E.g.:
it "marks a story as read when it is_read not malformed" do
login_as(default_user)
params = { is_read: true }.to_json
expect { put("/stories/#{story_one.id}", params:) }
.to change_record(story_one, :is_read).from(false).to(true)
end
request.body.read
comes through as ''
. If I instead set the env RAW_POST_DATA
it works as expected.
Expected behaviour
It seems like JSON params should work the same as in Rails 7.0.
Can you provide an example app?
You can see the behavior in this PR. Failed build here.
Is it possible that something has changed in Rails’ code?
@pirj that seems likely. However, it's documented behavior for RSpec, so not sure if it makes sense to change here as well.
This doc is also a cucumber spec, so it should fail when we’ll add 7.1 to the build matrix in #2692
I’ll keep this open just in case it doesn’t.
Did you try setting the json header like we document? This behaviour is a Rails behaviour and the cucumber test passes...
@JonRowe I didn't need the headers on Rails 7.0 for some reason, but adding them makes it work on Rails 7.1. I hadn't noticed those in the docs, so I suppose this can be closed unless you think there's something else to be done here.
Thanks for confirming, I'm going to close this because we don't really do anything here, we bring in the Rails test helpers and leave the rest to them bar setting routes and the application. If someone finds an improvement that can be made, e.g. bringing in another module etc or changing the order do comment / reopen.