Merge branch 'dev' into master

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

View File

@ -67,7 +67,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
else
record_hash = id_hash(id_from_record(record), record_type, true)
@ -123,7 +123,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

@ -81,6 +81,7 @@ RSpec.shared_context 'movie class' do
a.title = "Test Award #{i}"
a.actor_id = id
a.imdb_award_id = i * 10
a.year = 1990 + i
end
end
end
@ -111,7 +112,7 @@ RSpec.shared_context 'movie class' do
end
class Award
attr_accessor :id, :title, :actor_id, :imdb_award_id
attr_accessor :id, :title, :actor_id, :year, :imdb_award_id
end
class State
@ -226,6 +227,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