mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-23 06:16:50 +00:00
Fix: resource object identifier with nil id excludes id
This commit is contained in:
parent
92dde58f5f
commit
5916014b48
@ -38,8 +38,11 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
def as_json
|
||||
return nil if id.blank?
|
||||
{ id: id, type: type }
|
||||
if id.blank?
|
||||
{ type: type }
|
||||
else
|
||||
{ id: id.to_s, type: type }
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
@ -128,6 +128,13 @@ module ActiveModelSerializers
|
||||
assert_equal actual, expected
|
||||
end
|
||||
|
||||
def test_blank_id
|
||||
@model.id = nil
|
||||
actual = actual_resource_identifier_object(AuthorSerializer)
|
||||
expected = { type: expected_model_type }
|
||||
assert_equal actual, expected
|
||||
end
|
||||
|
||||
def test_id_defined_on_serializer
|
||||
actual = actual_resource_identifier_object(WithDefinedIdSerializer)
|
||||
expected = { id: 'special_id', type: expected_model_type }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user