File tree Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Expand file tree Collapse file tree 2 files changed +46
-5
lines changed Original file line number Diff line number Diff line change @@ -7,11 +7,11 @@ class Document
77 def initialize ( params = { } )
88 @data = params . fetch ( :data , :no_data )
99 @errors = params . fetch ( :errors , [ ] )
10- @meta = params . fetch ( :meta , nil )
11- @links = params . fetch ( :links , { } )
12- @fields = _symbolize_fields ( params . fetch ( :fields , { } ) )
13- @jsonapi = params . fetch ( :jsonapi , nil )
14- @include = JSONAPI ::IncludeDirective . new ( params . fetch ( :include , { } ) )
10+ @meta = params [ :meta ]
11+ @links = params [ :links ] || { }
12+ @fields = _symbolize_fields ( params [ :fields ] || { } )
13+ @jsonapi = params [ :jsonapi ]
14+ @include = JSONAPI ::IncludeDirective . new ( params [ :include ] || { } )
1515 end
1616
1717 def to_hash
Original file line number Diff line number Diff line change @@ -346,6 +346,47 @@ def as_jsonapi(options = {})
346346 expect ( actual ) . to eq ( expected )
347347 end
348348
349+ context 'when fields option is nil' do
350+ it 'does not filter out fields' do
351+ actual = subject . render ( data : @users [ 0 ] , fields : nil )
352+
353+ expected = {
354+ data : {
355+ type : 'users' ,
356+ id : '1' ,
357+ attributes : {
358+ name : 'User 1' ,
359+ address : '123 Example st.'
360+ } ,
361+ relationships : {
362+ posts : {
363+ links : {
364+ self : 'http://api.example.com/users/1/relationships/posts' ,
365+ related : {
366+ href : 'http://api.example.com/users/1/posts' ,
367+ meta : {
368+ do_not_use : true
369+ }
370+ }
371+ } ,
372+ meta : {
373+ deleted_posts : 5
374+ }
375+ }
376+ } ,
377+ links : {
378+ self : 'http://api.example.com/users/1'
379+ } ,
380+ meta : {
381+ user_meta : 'is_meta'
382+ }
383+ }
384+ }
385+
386+ expect ( actual ) . to eq ( expected )
387+ end
388+ end
389+
349390 it 'renders a toplevel meta' do
350391 actual = subject . render ( data : nil ,
351392 meta : { this : 'is_meta' } )
You can’t perform that action at this time.
0 commit comments