JSONAPI-Resources / JSONAPI-Resources/jsonapi-resources

ResourceSerializer serialized hash is nil

Open
#1,059 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
2.3k
Forks
546
PR merge metrics
No merged PRs in 30d

Description

Just updated to rails 5.

In a controller test, using minitest:

#From factory girl
user = create(:user)

resource = UserResource.new(user), nil)

serializer = JSONAPI::ResourceSerializer.new(UserResource)

output = serializer.serialize_to_hash(resource)

The resource is:

p resource

#<UserResource:0x0055ba82bd2170 
@model=#<User id: nil, name: "Mitchell-Gerhold">, 
@context=nil, 
@reload_needed=false, 
@changing=false, 
@save_needed=false>

But the serialized output is:

p output

{
    :data => nil
}

Any ideas?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the controller example and tracing JSONAPI::ResourceSerializer#serialize_to_hash with the shown UserResource state. Compare the resource's model and serializer input with the expected output, then verify that a regression check covers the nil :data result.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.