active_model_serializers icon indicating copy to clipboard operation
active_model_serializers copied to clipboard

Attributes are not listing for Polymorphic Comment Serializer

Open lassiter opened this issue 7 years ago • 0 comments

I'm running my RSpec tests and my polymorphic comments are not rendering as expected. It seems like it's not even being passed to the associated serializer in my PostSerializer. The PostSerializer is properly rendering the attributes and relationships as expected.

Expected behavior vs actual behavior

Expected (at this point):

[{"id"=>"292", "type"=>"comments", "attributes":
  "body": "Odio qui sit excepturi rerum.",
  "edit": null,
  "commentable_type": "Post",
  "commentable_id": 1,
  "member_id": 45,
  "attachment": null,
  "created_at": "2018-06-28 21:27:55 UTC",
  "updated_at": "2018-06-28 21:27:55 UTC",
  "links": {
    "self": "/v1/comments/1",
    "comment_replies": "/v1/comments/1/comment_replys",
    "member": "/v1/member.45"
  },
  "commentable": {
    "id": 1,
    "family_id": 2,
    "member_id": 20,
    "body": "Mollitia sed ut recusandae. Enim in et corrupti qui et.",
    "location": [
      53.9603963546022,
      -164.572115434852
    ],
    "edit": null,
    "attachment": null,
    "locked": false,
    "created_at": "2018-06-28 21:27:55 UTC",
    "updated_at": "2018-06-28 21:27:55 UTC",
    "links": {
      "self": "/v1/posts/1",
      "comments": "/v1/posts/1/comments",
      "member": "/v1/member.20"
    }
  },
  "member": "#<Member:0x00007fb069071ec8>",
  "reactions": [

  ]
}, ... more comments]

Actual:

json = JSON.parse(response.body)
actual = json["data"]["relationships"]["comments"]["data"] # array of comments
....
actual: [{"id"=>"292", "type"=>"comments"}, {"id"=>"293", "type"=>"comments"}, {"id"=>"294", "type"=>"comments"}]

Steps to reproduce

(e.g., detailed walkthrough, runnable script, example application) You can clone my project here: https://github.com/lassiter/FamNet/tree/8-Implement-Scope-for-Activity/Newsfeed Run bundle install Then run rspec spec/requests/posts_spec.rb -e "Post API :: Members / Same Family :: GET /posts/:id Posts#show and it shows the requested post's Comments with CommentReplies" and it has a binding.pry inside the test so you can inspect actual.

If you want to use the developer db: rails db:create && rails db:migrate && rails db:seed

It's currently a WIP, so apologies for the comments and commented code. Trying to get some custom things to render in there too like counts of likes, hearts and such.

Environment

ActiveModelSerializers Version (commit ref if not on tag): Gemfile.lock says active_model_serializers (0.10.7)

Output of ruby -e "puts RUBY_DESCRIPTION": ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin15]

OS Type & Version: macOS 10.11.6 El Capitan

Integrated application and version (e.g., Rails, Grape, etc): Rails 5.2

lassiter avatar Jun 29 '18 02:06 lassiter