Open BrennickL opened 3 years ago
@BrennickL it would be great to leave a more concrete example. I'm not sure I understand fully what do you mean by data arrays.
Btw, have you seen this section? https://github.com/jsonapi-rb/jsonapi-rspec#advanced-examples
@stas I think I understand what the OPs problem is because I'm facing a similar one. According to the docs, this should work:
expect(document['data']).to have_relationship(:posts).with_data([{ 'id' => '1', 'type' => 'posts' }])
However what you get if you pass in a structure to test like
{
"data"=> {
"id" => ..., "type" => "...",
"attribuites" => {...},
"relationships" => {
"posts": [
{ "data" => { "id" => "1", "type" => "posts" } },
{ "data" => { "id" => "2", "type" => "posts" } },
]
}
}
is
Failure/Error: expect(json["data"]).to have_relationship(:posts).with_data( [ { "id" => ...}, { "id" => "..." } ] )
TypeError:
no implicit conversion of String into Integer
because https://github.com/jsonapi-rb/jsonapi-rspec/blob/master/lib/jsonapi/rspec/relationships.rb#L9 can't handle arrays.
It actually expects relationships[:posts]
to be an object, but here it's an array.
@kassi would you be kind to review this test and help me understand how's that different from your example: https://github.com/jsonapi-rb/jsonapi-rspec/blob/master/spec/jsonapi/relationships_spec.rb#L35-L42
@kassi Your input is ill-formed. Your posts
should be an object containing a data
member that is an array, rather than being an array containing objects with a data
member:
{ "posts":
{ "data": [
{ "id" => "1", "type" => "posts" },
{ "id" => "2", "type" => "posts" }]
}
}
Cf. https://jsonapi.org/format/#document-resource-object-linkage
Expected Behavior
Should be able to handle Arrays.
Actual Behavior
Does not handle arrays.
Steps to Reproduce the Problem
Specifications
Version:
jsonapi-rspec (0.0.10) Summary: RSpec matchers for JSON API. Homepage: https://github.com/jsonapi-rb/jsonapi-rspec Path: /Users/brennick.langston/.rbenv/versions/2.3.7/lib/ruby/gems/2.3.0/gems/jsonapi-rspec-0.0.10
Ruby version: ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-darwin19]