0
votes

I'm trying to test a JSON endpoint (Rails 5) that is built using active model serializers gem (version 0.10.2) with the JSON adapter.

When I make the request from http://localhost:3000/api/posts I get the root node in the response so that it looks like the documentation:

{
  "posts": [{
    "id": 1,
    "title": "Awesome Post Tile",
    "content": "Post content"
  }]
}

but when I make the request in Rspec (version 3.5) like this:

get '/api/posts'

the root node doesn't come through, so the response body looks like this:

[{
   "id": 1,
   "title": "Awesome Post Tile",
   "content": "Post content"
}]

My adapter is being set in an initializer:

ActiveModelSerializers.config.adapter = :json

Is there something I'm doing wrong here? I don't really know enough about either as to whether this is an issue with AMS or Rspec or a setup problem on my part.

1

1 Answers

0
votes

It sounds like you might have enabled include_root_in_json for the development environment but not the test environment?

http://api.rubyonrails.org/classes/ActiveModel/Serializers/JSON.html