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.
- checksums.yaml +4 -4
- data/README.md +9 -111
- data/lib/jsonapi.rb +2 -18
- metadata +26 -45
- data/.gitignore +0 -36
- data/.travis.yml +0 -6
- data/Gemfile +0 -3
- data/Gemfile.lock +0 -36
- data/LICENSE +0 -21
- data/Rakefile +0 -7
- data/jsonapi_parser.gemspec +0 -24
- data/lib/jsonapi/attributes.rb +0 -41
- data/lib/jsonapi/document.rb +0 -126
- data/lib/jsonapi/error.rb +0 -27
- data/lib/jsonapi/exceptions.rb +0 -4
- data/lib/jsonapi/include_directive.rb +0 -67
- data/lib/jsonapi/include_directive/parser.rb +0 -66
- data/lib/jsonapi/jsonapi.rb +0 -19
- data/lib/jsonapi/link.rb +0 -41
- data/lib/jsonapi/links.rb +0 -34
- data/lib/jsonapi/parse.rb +0 -18
- data/lib/jsonapi/relationship.rb +0 -57
- data/lib/jsonapi/relationships.rb +0 -41
- data/lib/jsonapi/resource.rb +0 -46
- data/lib/jsonapi/resource_identifier.rb +0 -36
- data/lib/jsonapi/version.rb +0 -3
- data/spec/duplicates_spec.rb +0 -95
- data/spec/full_linkage_spec.rb +0 -161
- data/spec/include_directive/parser_spec.rb +0 -59
- data/spec/include_directive_spec.rb +0 -47
- data/spec/parser_spec.rb +0 -97
@@ -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
|
data/spec/parser_spec.rb
DELETED
@@ -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
|