File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
1
2
require 'json'
2
3
3
4
module JSONAPI
@@ -11,6 +12,7 @@ module JSONAPI
11
12
# objects in the primary data must have an id
12
13
# @return [JSON::API::Document]
13
14
def parse ( document , options = { } )
15
+ raise InvalidDocument , 'document cannot be nil' if document . nil?
14
16
hash = document . is_a? ( Hash ) ? document : JSON . parse ( document )
15
17
16
18
Document . new ( hash , options )
Original file line number Diff line number Diff line change 94
94
expect ( document . data . first . relationships . author . data . to_hash ) . to eq @author_data_hash
95
95
expect ( document . data . first . relationships . comments . data . map ( &:to_hash ) ) . to eq @comments_data_hash
96
96
end
97
+
98
+ it 'raises InvalidDocument on nil input' do
99
+ expect {
100
+ JSONAPI . parse ( nil )
101
+ } . to raise_error JSONAPI ::InvalidDocument
102
+ end
97
103
end
You can’t perform that action at this time.
0 commit comments