-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathrelationships_spec.rb
More file actions
69 lines (58 loc) · 1.75 KB
/
relationships_spec.rb
File metadata and controls
69 lines (58 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'spec_helper'
RSpec.describe JSONAPI::RSpec, '#have_relationship(s)' do
let(:doc) do
{
'relationships' => {
'user' => {
'data' => { 'id' => '1', 'type' => 'user' }
},
'comments' => {
'data' => [
{ 'id' => '1', 'type' => 'comment' },
{ 'id' => '2', 'type' => 'comment' }
]
}
}
}
end
it { expect(doc).not_to have_relationships('user', 'comments', 'authors') }
it { expect(doc).to have_relationships('user', 'comments') }
it { expect(doc).not_to have_relationship('authors') }
it { expect(doc).to have_relationship('user') }
it { expect(doc).to have_relationships('user', 'comments').exactly }
it { expect(doc).not_to have_relationships('comments').exactly }
it do
expect(doc).to have_relationship('user').with_data(
{ 'id' => '1', 'type' => 'user' }
)
end
it do
expect(doc).to have_relationship('comments').with_data(
[
{ 'id' => '1', 'type' => 'comment' },
{ 'id' => '2', 'type' => 'comment' }
]
)
end
it do
expect(doc).to have_relationship('comments').with_data(
include(have_id('1').and(have_type('comment')))
)
end
context 'with jsonapi indifferent hash enabled' do
before(:all) { ::RSpec.configuration.jsonapi_indifferent_hash = true }
after(:all) { ::RSpec.configuration.jsonapi_indifferent_hash = false }
it { expect(doc).to have_relationships(:user, :comments) }
it do
expect(doc).to have_relationship('user').with_data(id: '1', type: :user)
end
it do
expect(doc).to have_relationship('comments').with_data(
[
{ id: '1', type: 'comment' },
{ id: '2', type: 'comment' }
]
)
end
end
end