Skip to content

Commit dc2cae4

Browse files
aribouiusrichmolj
authored andcommitted
Fix bug causing missing fields (#80)
- Fixes bug caused by commit #0623552e153f0a1a30660e4d2b5bd0ddfee9d8a4
1 parent 7662531 commit dc2cae4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/jsonapi_compliable/util/render_options.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ def self.generate(object, query_hash, overrides = {})
1616
extra_fields = query_hash[:extra_fields]
1717

1818
# Ensure fields doesnt clobber extra fields
19-
if extra_fields.any? && fields.any?
20-
extra_fields.each { |k,v| fields[k] = fields[k].to_a + v }
19+
extra_fields.each do |k,v|
20+
fields[k] = fields[k] + v if fields[k]
2121
end
2222

2323
options = {}

spec/integration/rails/finders_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,22 @@ def json
304304
expect(hobby).to_not have_key('description')
305305
end
306306

307+
it 'allows extra fields and sparse fieldsets for multiple resources' do
308+
get :index, params: {
309+
include: 'hobbies,books',
310+
fields: { hobbies: 'name', books: 'title', },
311+
extra_fields: { hobbies: 'reason', books: 'alternate_title' },
312+
}
313+
hobby = json_includes('hobbies')[0]['attributes']
314+
book = json_includes('books')[0]['attributes']
315+
expect(hobby).to have_key('name')
316+
expect(hobby).to have_key('reason')
317+
expect(hobby).to_not have_key('description')
318+
expect(book).to have_key('title')
319+
expect(book).to have_key('alternate_title')
320+
expect(book).to_not have_key('pages')
321+
end
322+
307323
it 'does not duplicate results' do
308324
get :index, params: { include: 'hobbies' }
309325
author1_relationships = json['data'][0]['relationships']

0 commit comments

Comments
 (0)