Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Response is not rendered in requests specs with Rails 7.2 and ActiveModelSerializers #2806

Open
januszm opened this issue Oct 3, 2024 · 0 comments

Comments

@januszm
Copy link

januszm commented Oct 3, 2024

What Ruby, Rails and RSpec versions are you using?

Ruby version: 3.2.5
Rails version: 7.2.1
RSpec version: rspec-rails 7.0.1 , rspec-core 3.13.1

Observed behaviour

Before upgrade to Rails 7.1.2, both response and response.parsed_body returned properly rendered JSON for an API that uses Rails ActiveModelSerializers. After the upgrade, response contains the ActiveModelSerializers object simply returned as string, instead of the actual render.

> response
=> ...
 @stream=
  #<ActionDispatch::Response::Buffer:0x0000000135a98810
   @buf=["\"#<ActiveModelSerializers::Adapter::Attributes:0x0000000135add410>\""],

> response.body # or response.parsed_body, same result
=> "#<ActiveModelSerializers::Adapter::Attributes:0x000000012149dd70>"

Expected behaviour

In requests specs, response from a test for an API that uses ActiveModelSerializers and returns JSON, should return properly rendered JSON object, instead it returns the serializer instance.

Can you provide an example reproduction?

I created a brand new Rails 7.2 application with ActiveModelSerializers, but with stadard Rails setup and it properly renders the JSON object in the Integration test

test/integration/api_test.rb:7 ExampleTest#test_api:

    4: def test_api
    5:   Property.create(address: "155 Jackson", city: "Chicago")
    6:   get "/properties"
 => 7:   binding.pry
    8: end

> response
 @stream=
  #<ActionDispatch::Response::Buffer:0x0000000106629100
   @buf=
    ["[{\"address\":\"MyString\",\"city\":\"MyString\"},{\"address\":\"123 Jackson\",\"city\":\"Chicago\"}]"],

> response.parsed_body
=> [{"address"=>"MyString", "city"=>"MyString"}, {"address"=>"155 Jackson", "city"=>"Chicago"}]

which proves this is not an issue with ActiveModelSerializers, because it produces proper results with standard Rails 7.2.1 test suite. Not sure if this is an issue with rspec-rails or another gem from rspec group, so posting it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant