links key support

This commit is contained in:
mnauage 2018-03-12 12:19:19 -04:00 committed by Shishir Kakaraddi
parent fa09c29190
commit ecd7bbc793
4 changed files with 13 additions and 0 deletions

View File

@ -34,6 +34,7 @@ module FastJsonapi
def hash_for_one_record
serializable_hash = { data: nil }
serializable_hash[:meta] = @meta if @meta.present?
serializable_hash[:links] = @links if @links.present?
return serializable_hash unless @resource
@ -55,6 +56,7 @@ module FastJsonapi
serializable_hash[:data] = data
serializable_hash[:included] = included if @includes.present?
serializable_hash[:meta] = @meta if @meta.present?
serializable_hash[:links] = @links if @links.present?
serializable_hash
end
@ -69,6 +71,7 @@ module FastJsonapi
@known_included_objects = {}
@meta = options[:meta]
@links = options[:links]
if options[:include].present?
@includes = options[:include].delete_if(&:blank?).map(&:to_sym)

View File

@ -13,6 +13,8 @@ describe FastJsonapi::ObjectSerializer do
it 'returns correct hash when serializable_hash is called' do
options = {}
options[:meta] = { total: 2 }
options[:links] = { self: 'self' }
options[:include] = [:actors]
serializable_hash = CachingMovieSerializer.new([movie, movie], options).serializable_hash
@ -21,6 +23,7 @@ describe FastJsonapi::ObjectSerializer do
expect(serializable_hash[:data][0][:attributes].length).to eq 2
expect(serializable_hash[:meta]).to be_instance_of(Hash)
expect(serializable_hash[:links]).to be_instance_of(Hash)
expect(serializable_hash[:included]).to be_instance_of(Array)
expect(serializable_hash[:included][0]).to be_instance_of(Hash)
@ -30,6 +33,7 @@ describe FastJsonapi::ObjectSerializer do
expect(serializable_hash[:data]).to be_instance_of(Hash)
expect(serializable_hash[:meta]).to be nil
expect(serializable_hash[:links]).to be nil
expect(serializable_hash[:included]).to be nil
end

View File

@ -7,6 +7,7 @@ describe FastJsonapi::ObjectSerializer do
it 'returns correct hash when serializable_hash is called' do
options = {}
options[:meta] = { total: 2 }
options[:links] = { self: 'self' }
options[:include] = [:actors]
serializable_hash = MovieSerializer.new([movie, movie], options).serializable_hash
@ -15,6 +16,7 @@ describe FastJsonapi::ObjectSerializer do
expect(serializable_hash[:data][0][:attributes].length).to eq 2
expect(serializable_hash[:meta]).to be_instance_of(Hash)
expect(serializable_hash[:links]).to be_instance_of(Hash)
expect(serializable_hash[:included]).to be_instance_of(Array)
expect(serializable_hash[:included][0]).to be_instance_of(Hash)
@ -24,6 +26,7 @@ describe FastJsonapi::ObjectSerializer do
expect(serializable_hash[:data]).to be_instance_of(Hash)
expect(serializable_hash[:meta]).to be nil
expect(serializable_hash[:links]).to be nil
expect(serializable_hash[:included]).to be nil
end

View File

@ -7,6 +7,7 @@ describe FastJsonapi::ObjectSerializer do
it 'returns correct hash when serializable_hash is called' do
options = {}
options[:meta] = { total: 2 }
options[:links] = { self: 'self' }
options[:include] = [:actors]
serializable_hash = MovieSerializer.new([movie_struct, movie_struct], options).serializable_hash
@ -15,6 +16,7 @@ describe FastJsonapi::ObjectSerializer do
expect(serializable_hash[:data][0][:attributes].length).to eq 2
expect(serializable_hash[:meta]).to be_instance_of(Hash)
expect(serializable_hash[:links]).to be_instance_of(Hash)
expect(serializable_hash[:included]).to be_instance_of(Array)
expect(serializable_hash[:included][0]).to be_instance_of(Hash)
@ -24,6 +26,7 @@ describe FastJsonapi::ObjectSerializer do
expect(serializable_hash[:data]).to be_instance_of(Hash)
expect(serializable_hash[:meta]).to be nil
expect(serializable_hash[:links]).to be nil
expect(serializable_hash[:included]).to be nil
expect(serializable_hash[:data][:id]).to eq movie_struct.id.to_s
end