-
Notifications
You must be signed in to change notification settings - Fork 10
json_related_link helper doesn't seem to work? #16
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
Comments
The mentioned snippets: jsonapi_spec_helpers/lib/jsonapi_spec_helpers/helpers.rb Lines 11 to 15 in 2ef4f0a
|
Sorry for the lack of docs - I think I needed it for something short-term but wasn't sure if it should be public API. This was actually a helper to grab http links, ie self/related links. It sounds like we need a helper to grab the id/type of a given relationship. I'm thinking something like this, your thoughts? jsonapi_related(json_item) # => [{ id: 1, type: 'posts' }]
jsonapi_related(json_item, true) # => [1,2,3] just ids This should be able to take the id/type of the It could use a separate helper to find the item (incl relationships) anywhere in the payload. |
I suppose outlining my usage would have helped. Sorry. We are serializing an {
"data": {
"id": "kJ2MCFW2JJmpVLn4xmM6dszx",
"type": "invitations",
"attributes": {
"nickname": "frye",
"accepted_at": "2018-04-24T03:00:20.748Z",
"sent_at": "2018-04-24T03:00:19.474Z"
},
"relationships": {
"sender": {
"links": {
"related": "http://localhost:5000/api/accounts/4"
},
"data": {
"type": "accounts",
"id": "4"
}
}
},
"links": {
"self": "http://localhost:5000/api/invitations/kJ2MCFW2JJmpVLn4xmM6dszx"
}
},
"meta": {},
"jsonapi": {
"version": "1.0"
}
} I wanted to make sure the "sender" link was present, and the expected value. I thought I could use But as I said, Anyhow... that's my use case. Does that clarify things at all? Provide a way forward? |
OK this helps! Yeah the purpose of
I'm with you on the spec. But I think jsonapi-rb will always generate the href, no? Are you using an alternate serialization library? Apologies on this method - I've been avoiding links on my projects (long story) so I used it briefly and haven't been supporting it well. I see some old code using it like expect(json_related_link(json['data'][0], 'servers')).to eq('thelink') It seems like a helper method might be missing though to clean that up even further |
Or... I don't understand how to use it. There are no specs for it, so it's hard to know which is the case. I'm trying to use it to assert that a certain relationship is present in the JSON. The problem is, the
json_item
helper doesn't pull thedata['relationships']
over, and so thejson_related_link
helper fails b/cpayload['relationships']
isnil
.I tried to fix the☹️
json_item
helper to bring the relationships over, but then I'd need to update the associated payload registration b/c there was an unaccounted for key. At that point I determined that I didn't fully understand how things were intended to work. Thus, an Issue rather than a PR.The text was updated successfully, but these errors were encountered: