mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06: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
|
end
|
||||||
|
|
||||||
def as_json
|
def as_json
|
||||||
return nil if id.blank?
|
if id.blank?
|
||||||
{ id: id, type: type }
|
{ type: type }
|
||||||
|
else
|
||||||
|
{ id: id.to_s, type: type }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
@ -128,6 +128,13 @@ module ActiveModelSerializers
|
|||||||
assert_equal actual, expected
|
assert_equal actual, expected
|
||||||
end
|
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
|
def test_id_defined_on_serializer
|
||||||
actual = actual_resource_identifier_object(WithDefinedIdSerializer)
|
actual = actual_resource_identifier_object(WithDefinedIdSerializer)
|
||||||
expected = { id: 'special_id', type: expected_model_type }
|
expected = { id: 'special_id', type: expected_model_type }
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user