json-api-vanilla 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/json-api-vanilla/parser.rb +3 -6
- data/lib/json-api-vanilla/version.rb +1 -1
- data/spec/json-api-vanilla/diff_spec.rb +12 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d265b20f67d08ed43d7400a31c9967a8d889d28
|
4
|
+
data.tar.gz: 35615f3284b5251ddaa6f938a12a81233a6455da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d5c43003af1b69ad6765b133413db6f34788c153e49ed733e951d84121b4b652326dd22d7ed5a3c7df710efb15dead48f10b76d5629b3336ba2a639315bdfb4
|
7
|
+
data.tar.gz: 52d80f203986990a057bece26ffee84eaa0df3a1036de155b325c37ce68c2c023a6c91542e15a4a4db033e85c8b46d51c8c0ddf4563c1a1efad35d42ce1967fa
|
@@ -173,12 +173,9 @@ module JSON::Api::Vanilla
|
|
173
173
|
# @raise [InvalidRootStructure] raised if the document doesn't have
|
174
174
|
# data, errors nor meta objects at its root.
|
175
175
|
def self.naive_validate(hash)
|
176
|
-
root_keys = %
|
177
|
-
present_structures = root_keys.map
|
178
|
-
|
179
|
-
obj.respond_to?(:empty?) ? !obj.empty? : !!obj
|
180
|
-
end
|
181
|
-
if present_structures.none?
|
176
|
+
root_keys = %i(data errors meta)
|
177
|
+
present_structures = root_keys & hash.keys.map(&:to_sym)
|
178
|
+
if present_structures.empty?
|
182
179
|
raise InvalidRootStructure.new("JSON:API document must contain at least one of these objects: #{root_keys.join(', ')}")
|
183
180
|
end
|
184
181
|
end
|
@@ -85,4 +85,16 @@ describe JSON::Api::Vanilla do
|
|
85
85
|
JSON::Api::Vanilla.parse(json)
|
86
86
|
end.to raise_error(JSON::Api::Vanilla::InvalidRootStructure)
|
87
87
|
end
|
88
|
+
|
89
|
+
it "should not raise any errors if the document contains root elements as symbols" do
|
90
|
+
expect do
|
91
|
+
JSON::Api::Vanilla.naive_validate(data: { id: 1, type: 'mvp' })
|
92
|
+
end.to_not raise_error
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not raise any errors if the document contains an empty array for data" do
|
96
|
+
expect do
|
97
|
+
JSON::Api::Vanilla.naive_validate(data: [])
|
98
|
+
end.to_not raise_error
|
99
|
+
end
|
88
100
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json-api-vanilla
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thaddée Tyl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Given a JSON API string, we parse it and return a document that can be
|
14
14
|
browsed — as if the objects defined in the file were plain old Ruby objects.
|
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
54
54
|
version: '0'
|
55
55
|
requirements: []
|
56
56
|
rubyforge_project:
|
57
|
-
rubygems_version: 2.
|
57
|
+
rubygems_version: 2.6.11
|
58
58
|
signing_key:
|
59
59
|
specification_version: 4
|
60
60
|
summary: Deserialize JSON API formats into vanilla Ruby objects.
|