Fix error on defining anonymous serializer class, fixes #353
This commit is contained in:
		
							parent
							
								
									21ae4aaa0a
								
							
						
					
					
						commit
						8d8e5c3059
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user