jsonapi 0.1.1.beta2 → 0.1.1.beta6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +0,0 @@
1
- require 'jsonapi/include_directive'
2
-
3
- describe JSONAPI::IncludeDirective, '.key?' do
4
- it 'handles existing keys' do
5
- str = 'posts.comments'
6
- include_directive = JSONAPI::IncludeDirective.new(str)
7
-
8
- expect(include_directive.key?(:posts)).to be_truthy
9
- end
10
-
11
- it 'handles absent keys' do
12
- str = 'posts.comments'
13
- include_directive = JSONAPI::IncludeDirective.new(str)
14
-
15
- expect(include_directive.key?(:author)).to be_falsy
16
- end
17
-
18
- it 'handles wildcards' do
19
- str = 'posts.*'
20
- include_directive = JSONAPI::IncludeDirective.new(
21
- str, allow_wildcard: true)
22
-
23
- expect(include_directive[:posts].key?(:author)).to be_truthy
24
- expect(include_directive[:posts][:author].key?(:comments)).to be_falsy
25
- end
26
-
27
- it 'handles wildcards' do
28
- str = 'posts.**'
29
- include_directive = JSONAPI::IncludeDirective.new(
30
- str, allow_wildcard: true)
31
-
32
- expect(include_directive[:posts].key?(:author)).to be_truthy
33
- expect(include_directive[:posts][:author].key?(:comments)).to be_truthy
34
- end
35
- end
36
-
37
- describe JSONAPI::IncludeDirective, '.to_string' do
38
- it 'works' do
39
- str = 'friends,comments.author,posts.author,posts.comments.author'
40
- include_directive = JSONAPI::IncludeDirective.new(str)
41
- expected = include_directive.to_hash
42
- actual = JSONAPI::IncludeDirective.new(include_directive.to_string)
43
- .to_hash
44
-
45
- expect(actual).to eq expected
46
- end
47
- end
@@ -1,97 +0,0 @@
1
- require 'jsonapi'
2
-
3
- describe JSONAPI, '#parse' do
4
- before(:all) do
5
- @author_links_hash = {
6
- 'self' => 'http://example.com/articles/1/relationships/author',
7
- 'related' => 'http://example.com/articles/1/author'
8
- }
9
- @author_data_hash = { 'type' => 'people', 'id' => '9' }
10
- @comments_data_hash = [
11
- { 'type' => 'comments', 'id' => '5' },
12
- { 'type' => 'comments', 'id' => '12' }
13
- ]
14
- @article_relationships_hash = {
15
- 'author' => {
16
- 'links' => @author_links_hash,
17
- 'data' => @author_data_hash
18
- },
19
- 'journal' => {
20
- 'data' => nil
21
- },
22
- 'comments' => {
23
- 'links' => {
24
- 'self' => 'http://example.com/articles/1/relationships/comments',
25
- 'related' => 'http://example.com/articles/1/comments'
26
- },
27
- 'data' => @comments_data_hash
28
- }
29
- }
30
- @article_attributes_hash = { 'title' => 'JSON API paints my bikeshed!' }
31
- @article_links_hash = { 'self' => 'http://example.com/articles/1' }
32
- @data_hash = [{
33
- 'type' => 'articles',
34
- 'id' => '1',
35
- 'attributes' => @article_attributes_hash,
36
- 'links' => @article_links_hash,
37
- 'relationships' => @article_relationships_hash
38
- }]
39
- @meta_hash = {
40
- 'count' => '13'
41
- }
42
-
43
- @payload = {
44
- 'data' => @data_hash,
45
- 'meta' => @meta_hash
46
- }
47
- end
48
-
49
- it 'works' do
50
- document = JSONAPI.parse(@payload)
51
-
52
- expect(document.meta.keys).to eq ['count']
53
- expect(document.meta['count']).to eq '13'
54
- expect(document.data.first.links.keys).to eq ['self']
55
- expect(document.data.first.links.defined?(:self)).to be_truthy
56
- expect(document.data.first.links.self.value).to eq 'http://example.com/articles/1'
57
- expect(document.data.first.attributes.keys).to eq ['title']
58
- expect(document.data.first.attributes.defined?(:title)).to be_truthy
59
- expect(document.data.first.attributes.title).to eq 'JSON API paints my bikeshed!'
60
- expect(document.data.first.relationships.keys).to eq %w(author journal comments)
61
- expect(document.data.first.relationships.defined?(:author)).to be_truthy
62
- expect(document.data.first.relationships.author.collection?).to be_falsy
63
- expect(document.data.first.relationships.author.data.id).to eq '9'
64
- expect(document.data.first.relationships.author.data.type).to eq 'people'
65
- expect(document.data.first.relationships.author.links.keys).to eq ['self', 'related']
66
- expect(document.data.first.relationships.author.links.defined?(:self)).to be_truthy
67
- expect(document.data.first.relationships.author.links.self.value).to eq 'http://example.com/articles/1/relationships/author'
68
- expect(document.data.first.relationships.author.links.defined?(:related)).to be_truthy
69
- expect(document.data.first.relationships.author.links.related.value).to eq 'http://example.com/articles/1/author'
70
- expect(document.data.first.relationships.defined?(:comments)).to be_truthy
71
- expect(document.data.first.relationships.comments.collection?).to be_truthy
72
- expect(document.data.first.relationships.comments.data.size).to eq 2
73
- expect(document.data.first.relationships.comments.data[0].id).to eq '5'
74
- expect(document.data.first.relationships.comments.data[0].type).to eq 'comments'
75
- expect(document.data.first.relationships.comments.data[1].id).to eq '12'
76
- expect(document.data.first.relationships.comments.data[1].type).to eq 'comments'
77
- expect(document.data.first.relationships.comments.links.keys).to eq ['self', 'related']
78
- expect(document.data.first.relationships.comments.links.defined?(:self)).to be_truthy
79
- expect(document.data.first.relationships.comments.links.self.value).to eq 'http://example.com/articles/1/relationships/comments'
80
- expect(document.data.first.relationships.comments.links.defined?(:related)).to be_truthy
81
- expect(document.data.first.relationships.comments.links.related.value).to eq 'http://example.com/articles/1/comments'
82
- expect(document.data.first.relationships.defined?(:journal)).to be_truthy
83
- expect(document.data.first.relationships.journal.collection?).to be_falsy
84
- expect(document.data.first.relationships.journal.data).to eq nil
85
-
86
- expect(document.to_hash).to eq @payload
87
- expect(document.data.map(&:to_hash)).to eq @data_hash
88
-
89
- expect(document.data.first.attributes.to_hash).to eq @article_attributes_hash
90
- expect(document.data.first.links.to_hash).to eq @article_links_hash
91
- expect(document.data.first.relationships.to_hash).to eq @article_relationships_hash
92
-
93
- expect(document.data.first.relationships.author.links.to_hash).to eq @author_links_hash
94
- expect(document.data.first.relationships.author.data.to_hash).to eq @author_data_hash
95
- expect(document.data.first.relationships.comments.data.map(&:to_hash)).to eq @comments_data_hash
96
- end
97
- end