Skip to content

Question: Programmatically invoking ArraySerializer for JSONAPI #1002

Closed
@shicholas

Description

@shicholas

I am trying to write a controller spec for something that already works as expected, namely:

  render json: products, include: 'category', meta: pagination

which gives me the JSON API that I expect. I'm trying to write something like this in my tests:

product = FactoryGirl.create(:product)
expected_json = ActiveModel::Serializer::Adapter.create(
  ActiveModel::Serializer::ArraySerializer.new(
    [product], 
    included: 'category'
    meta: pagination
  )
).to_json

but I can't seem to get the included part to display (the data and meta attributes work just fine). Any help to programatically create a JSON document w/ included would be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions