Skip to content

Commit b0a2582

Browse files
sa73917stas
authored andcommitted
Create relationships spec based on attributes and links spec
1 parent 4a2ad54 commit b0a2582

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

spec/jsonapi/relationships_spec.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
RSpec.describe JSONAPI::RSpec do
2+
json_doc =
3+
{
4+
'relationships' => {
5+
'posts' => {
6+
'data' => {
7+
'id' => '1',
8+
'type' => 'posts'
9+
}
10+
},
11+
'comments' => {
12+
'data' => [{
13+
'id' => '1',
14+
'type' => 'posts'
15+
}, {
16+
'id' => '2',
17+
'type' => 'hides'
18+
}]
19+
}
20+
}
21+
}
22+
23+
describe '#have_relationship' do
24+
context 'when relationships is present' do
25+
it { expect(json_doc).to have_relationship('posts') }
26+
it { expect(json_doc).not_to have_relationship('mails') }
27+
it { expect(json_doc).to have_relationship('posts').with_data({ 'id' => '1', 'type' => 'posts' }) }
28+
it do
29+
expect(json_doc).to have_relationship('comments').with_data(
30+
[{ 'id' => '1', 'type' => 'posts' }, { 'id' => '2', 'type' => 'hides' }]
31+
)
32+
end
33+
end
34+
35+
context 'when relationships is not present' do
36+
it { expect({}).not_to have_relationship('posts') }
37+
end
38+
end
39+
40+
describe '#have_relationships' do
41+
context 'when relationships is present' do
42+
it { expect(json_doc).to have_relationships('posts', 'comments') }
43+
it { expect(json_doc).not_to have_relationships('posts', 'comments', 'mails') }
44+
end
45+
46+
context 'when relationships is not present' do
47+
it { expect({}).not_to have_relationships('posts', 'comments') }
48+
end
49+
end
50+
end

0 commit comments

Comments
 (0)