mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-22 22:06:50 +00:00
return nil if id is nil
This commit is contained in:
parent
4b0c230d76
commit
28a172e66a
@ -55,7 +55,6 @@ module ActiveModelSerializers
|
|||||||
else
|
else
|
||||||
association.reflection.type.to_s
|
association.reflection.type.to_s
|
||||||
end
|
end
|
||||||
# TODO: probably return nil if association.object is nil?
|
|
||||||
ResourceIdentifier.for_type_with_id(type, id, serializable_resource_options)
|
ResourceIdentifier.for_type_with_id(type, id, serializable_resource_options)
|
||||||
else
|
else
|
||||||
# TODO(BF): Process relationship without evaluating lazy_association
|
# TODO(BF): Process relationship without evaluating lazy_association
|
||||||
|
|||||||
@ -13,7 +13,7 @@ module ActiveModelSerializers
|
|||||||
type = inflect_type(type)
|
type = inflect_type(type)
|
||||||
type = type_for(:no_class_needed, type, options)
|
type = type_for(:no_class_needed, type, options)
|
||||||
if id.blank?
|
if id.blank?
|
||||||
{ type: type }
|
nil
|
||||||
else
|
else
|
||||||
{ id: id.to_s, type: type }
|
{ id: id.to_s, type: type }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -36,6 +36,7 @@ module ActiveModelSerializers
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_relationship_with_nil_model_and_belongs_to_id_on_self
|
def test_relationship_with_nil_model_and_belongs_to_id_on_self
|
||||||
|
original_config = ActiveModelSerializers.config.jsonapi_use_foreign_key_on_belongs_to_relationship
|
||||||
ActiveModelSerializers.config.jsonapi_use_foreign_key_on_belongs_to_relationship = true
|
ActiveModelSerializers.config.jsonapi_use_foreign_key_on_belongs_to_relationship = true
|
||||||
|
|
||||||
expected = { data: nil }
|
expected = { data: nil }
|
||||||
@ -46,7 +47,10 @@ module ActiveModelSerializers
|
|||||||
actual = build_serializer_and_serialize_relationship(model, relationship_name) do
|
actual = build_serializer_and_serialize_relationship(model, relationship_name) do
|
||||||
belongs_to :blog
|
belongs_to :blog
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_equal(expected, actual)
|
assert_equal(expected, actual)
|
||||||
|
ensure
|
||||||
|
ActiveModelSerializers.config.jsonapi_use_foreign_key_on_belongs_to_relationship = original_config
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_relationship_with_data_array
|
def test_relationship_with_data_array
|
||||||
|
|||||||
@ -147,8 +147,7 @@ module ActiveModelSerializers
|
|||||||
def test_for_type_with_id_given_blank_id
|
def test_for_type_with_id_given_blank_id
|
||||||
id = ''
|
id = ''
|
||||||
actual = ResourceIdentifier.for_type_with_id('admin_user', id, {})
|
actual = ResourceIdentifier.for_type_with_id('admin_user', id, {})
|
||||||
expected = { type: 'admin-users' }
|
assert_nil actual
|
||||||
assert_equal actual, expected
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_for_type_with_id_inflected
|
def test_for_type_with_id_inflected
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user