Skip to content

Commit 4f7d263

Browse files
authored
Improve test coverage. (#5)
1 parent 7e97593 commit 4f7d263

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

spec/include_directive/parser_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,12 @@
7171

7272
expect(hash).to eq expected
7373
end
74+
75+
it 'handles invalid input' do
76+
args = Object.new
77+
hash = JSONAPI::IncludeDirective::Parser.parse_include_args(args)
78+
expected = {}
79+
80+
expect(hash).to eq expected
81+
end
7482
end

spec/renderer_spec.rb

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def jsonapi_id
8484
end
8585

8686
def jsonapi_related(included)
87-
included.include?(:author) ? { author: @author } : {}
87+
included.include?(:author) ? { author: [@author] } : {}
8888
end
8989

9090
def as_jsonapi(options = {})
@@ -391,4 +391,27 @@ def as_jsonapi(options = {})
391391

392392
expect(actual).to eq(expected)
393393
end
394+
395+
class ErrorResource
396+
def initialize(id, title)
397+
@id = id
398+
@title = title
399+
end
400+
401+
def as_jsonapi
402+
{ id: @id, title: @title }
403+
end
404+
end
405+
406+
it 'renders errors' do
407+
errors = [ErrorResource.new('1', 'Not working'),
408+
ErrorResource.new('2', 'Works poorly')]
409+
actual = JSONAPI.render(errors: errors)
410+
expected = {
411+
errors: [{ id: '1', title: 'Not working' },
412+
{ id: '2', title: 'Works poorly' }]
413+
}
414+
415+
expect(actual).to eq(expected)
416+
end
394417
end

0 commit comments

Comments
 (0)