json-api-vanilla 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c5760a75bcea2f2870e2641f246b36bd63ffcdb9
4
- data.tar.gz: 8208a9f5cd8089bf6c356e4548c3d22c4ceea73a
3
+ metadata.gz: 0d265b20f67d08ed43d7400a31c9967a8d889d28
4
+ data.tar.gz: 35615f3284b5251ddaa6f938a12a81233a6455da
5
5
  SHA512:
6
- metadata.gz: 6c30f227cd52a825173bcfc39ca3f319c9d3796e812542611482e2a29ed65cd4a9427d537453498524891c669abbcfad6d7b5490708784831be17f1bc27062af
7
- data.tar.gz: aa5d645da7d059f6bb1f436093b6bb3161174f777b8485eac56e3de5fda5700700f84bc77f40acf14580b25ef155181bb680478f5e766a483ec19ad1b3c9acc6
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 = %w(data errors meta)
177
- present_structures = root_keys.map do |key|
178
- obj = hash[key]
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
@@ -2,7 +2,7 @@
2
2
  module JSON
3
3
  module Api
4
4
  module Vanilla
5
- VERSION = '1.0.0'
5
+ VERSION = '1.0.1'
6
6
  end
7
7
  end
8
8
  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.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: 2016-10-14 00:00:00.000000000 Z
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.5.1
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.