Fix error on defining anonymous serializer class, fixes #353

This commit is contained in:
Daniel Illi 2018-11-22 10:58:42 +01:00 committed by Kevin Pheasey
parent 21ae4aaa0a
commit 8d8e5c3059
2 changed files with 15 additions and 8 deletions

View File

@ -130,7 +130,7 @@ module FastJsonapi
return @reflected_record_type if defined?(@reflected_record_type)
@reflected_record_type ||= begin
if self.name.end_with?('Serializer')
if self.name && self.name.end_with?('Serializer')
self.name.split('::').last.chomp('Serializer').underscore.to_sym
end
end

View File

@ -314,13 +314,6 @@ describe FastJsonapi::ObjectSerializer do
expect(BlahBlahSerializer.record_type).to be :blah_blah
end
it 'shouldnt set default_type for a serializer that doesnt follow convention' do
class BlahBlahSerializerBuilder
include FastJsonapi::ObjectSerializer
end
expect(BlahBlahSerializerBuilder.record_type).to be_nil
end
it 'should set default_type for a namespaced serializer' do
module V1
class BlahSerializer
@ -329,6 +322,20 @@ describe FastJsonapi::ObjectSerializer do
end
expect(V1::BlahSerializer.record_type).to be :blah
end
it 'shouldnt set default_type for a serializer that doesnt follow convention' do
class BlahBlahSerializerBuilder
include FastJsonapi::ObjectSerializer
end
expect(BlahBlahSerializerBuilder.record_type).to be_nil
end
it 'shouldnt set default_type for an anonymous serializer' do
serializer_class = Class.new do
include FastJsonapi::ObjectSerializer
end
expect(serializer_class.record_type).to be_nil
end
end
context 'when serializing included, serialize any links' do