Merge branch 'dev' into add_meta

This commit is contained in:
Manoj M J 2018-07-21 09:39:33 +05:30 committed by GitHub
commit 099eb606bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 3 deletions

View File

@ -72,7 +72,7 @@ module FastJsonapi
temp_hash[:links] = links_hash(record, params) if data_links.present?
temp_hash
end
record_hash[:relationships] = record_hash[:relationships].merge(relationships_hash(record, uncachable_relationships_to_serialize, params)) if uncachable_relationships_to_serialize.present?
record_hash[:relationships] = record_hash[:relationships].merge(relationships_hash(record, uncachable_relationships_to_serialize, fieldset, params)) if uncachable_relationships_to_serialize.present?
record_hash[:meta] = meta_hash(record, params) if meta_to_serialize.present?
record_hash
else
@ -130,7 +130,7 @@ module FastJsonapi
included_objects.each do |inc_obj|
if remaining_items(items)
serializer_records = serializer.get_included_records(inc_obj, remaining_items(items), known_included_objects, fieldsets)
serializer_records = serializer.get_included_records(inc_obj, remaining_items(items), known_included_objects, fieldsets, params)
included_records.concat(serializer_records) unless serializer_records.empty?
end

View File

@ -310,6 +310,23 @@ describe FastJsonapi::ObjectSerializer do
end
end
context 'when serializing included, params should be available in any serializer' do
subject(:serializable_hash) do
options = {}
options[:include] = [:"actors.awards"]
options[:params] = { include_award_year: true }
MovieSerializer.new(movie, options).serializable_hash
end
let(:actor) { movie.actors.first }
let(:award) { actor.awards.first }
let(:year) { award.year }
it 'passes params to deeply nested includes' do
expect(year).to_not be_blank
expect(serializable_hash[:included][0][:attributes][:year]).to eq year
end
end
context 'when is_collection option present' do
subject { MovieSerializer.new(resource, is_collection_options).serializable_hash }

View File

@ -80,6 +80,7 @@ RSpec.shared_context 'movie class' do
a.id = i
a.title = "Test Award #{i}"
a.actor_id = id
a.year = 1990 + i
end
end
end
@ -110,7 +111,7 @@ RSpec.shared_context 'movie class' do
end
class Award
attr_accessor :id, :title, :actor_id
attr_accessor :id, :title, :actor_id, :year
end
class State
@ -225,6 +226,11 @@ RSpec.shared_context 'movie class' do
class AwardSerializer
include FastJsonapi::ObjectSerializer
attributes :id, :title
attribute :year, if: Proc.new { |record, params|
params[:include_award_year].present? ?
params[:include_award_year] :
false
}
belongs_to :actor
end