From 77c7af2a5edd9ca0e1dee5207ae0470aaea8adb5 Mon Sep 17 00:00:00 2001 From: Erol Date: Tue, 17 Jul 2018 11:54:48 +0800 Subject: [PATCH] Set the record type for inherited serializers --- lib/fast_jsonapi/object_serializer.rb | 1 + spec/lib/object_serializer_inheritance_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/fast_jsonapi/object_serializer.rb b/lib/fast_jsonapi/object_serializer.rb index 7d58e67..2cc1b35 100644 --- a/lib/fast_jsonapi/object_serializer.rb +++ b/lib/fast_jsonapi/object_serializer.rb @@ -119,6 +119,7 @@ module FastJsonapi subclass.race_condition_ttl = race_condition_ttl subclass.data_links = data_links subclass.cached = cached + subclass.set_type(subclass.reflected_record_type) if subclass.reflected_record_type end def reflected_record_type diff --git a/spec/lib/object_serializer_inheritance_spec.rb b/spec/lib/object_serializer_inheritance_spec.rb index 8cf5b53..beb7487 100644 --- a/spec/lib/object_serializer_inheritance_spec.rb +++ b/spec/lib/object_serializer_inheritance_spec.rb @@ -95,6 +95,11 @@ describe FastJsonapi::ObjectSerializer do has_one :account end + it 'sets the correct record type' do + expect(EmployeeSerializer.reflected_record_type).to eq :employee + expect(EmployeeSerializer.record_type).to eq :employee + end + context 'when testing inheritance of attributes' do it 'includes parent attributes' do