File tree Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Expand file tree Collapse file tree 2 files changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,7 @@ def self.serialize(objects, options = {})
222222 options [ :context ] = options . delete ( 'context' ) || options [ :context ] || { }
223223 options [ :skip_collection_check ] = options . delete ( 'skip_collection_check' ) || options [ :skip_collection_check ] || false
224224 options [ :base_url ] = options . delete ( 'base_url' ) || options [ :base_url ]
225+ options [ :meta ] = options . delete ( 'meta' ) || options [ :meta ]
225226
226227 # Normalize includes.
227228 includes = options [ :include ]
@@ -273,6 +274,7 @@ def self.serialize(objects, options = {})
273274 result = {
274275 'data' => primary_data ,
275276 }
277+ result [ 'meta' ] = options [ :meta ] if options [ :meta ]
276278
277279 # If 'include' relationships are given, recursively find and include each object.
278280 if includes
Original file line number Diff line number Diff line change @@ -333,6 +333,14 @@ def serialize_primary(object, options = {})
333333 'data' => serialize_primary ( post , { serializer : MyApp ::PostSerializer } ) ,
334334 } )
335335 end
336+ it 'can include a top level meta node' do
337+ post = create ( :post )
338+ meta = { authors : [ 'Yehuda Katz' , 'Steve Klabnik' ] , copyright : 'Copyright 2015 Example Corp.' }
339+ expect ( JSONAPI ::Serializer . serialize ( post , meta : meta ) ) . to eq ( {
340+ 'meta' => meta ,
341+ 'data' => serialize_primary ( post , { serializer : MyApp ::PostSerializer } ) ,
342+ } )
343+ end
336344 it 'can serialize a single object with an `each` method by passing skip_collection_check: true' do
337345 post = create ( :post )
338346 post . define_singleton_method ( :each ) do
You can’t perform that action at this time.
0 commit comments