Skip to content

Commit 4b3ce2e

Browse files
Add failing test for issue jsonapi-suite#8
1 parent 7d11d5e commit 4b3ce2e

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

spec/assert_payload_spec.rb

+46-8
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@
3535
end
3636
end
3737

38-
context 'when payload is valid' do
39-
let(:post_record) do
40-
double \
41-
id: 1,
42-
title: 'post title',
43-
description: 'post description',
44-
views: 100
45-
end
38+
let(:post_record) do
39+
double \
40+
id: 1,
41+
title: 'post title',
42+
description: 'post description',
43+
views: 100
44+
end
4645

46+
context 'when payload is valid' do
4747
it 'passes assertion' do
4848
assert_payload(:post, post_record, json_item)
4949
end
@@ -235,5 +235,43 @@
235235
end
236236
end
237237
end
238+
239+
context 'when payload contains a "relationship-only" item' do
240+
before do
241+
JsonapiSpecHelpers::Payload.register(:no_attribute_item) do
242+
end
243+
end
244+
245+
let(:no_attribute_record) do
246+
double \
247+
id: 1,
248+
posts: post_record
249+
end
250+
251+
let(:json) do
252+
{
253+
'data' => {
254+
'type' => 'no_attributes_items',
255+
'id' => '1',
256+
'relationships' => {
257+
'posts' => {
258+
'data' => [
259+
{'type' => 'posts', 'id' => '1'}
260+
]
261+
}
262+
}
263+
}
264+
}
265+
end
266+
267+
it 'still properly throws when no item is present' do
268+
empty_json_item = {'id' => nil, 'jsonapi_type' => nil}
269+
expect {
270+
assert_payload(:no_attribute_item, no_attribute_record, empty_json_item)
271+
}.to raise_error(
272+
RSpec::Expectations::ExpectationNotMetError
273+
)
274+
end
275+
end
238276
end
239277
end

0 commit comments

Comments
 (0)