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
|
||||
association.reflection.type.to_s
|
||||
end
|
||||
# TODO: probably return nil if association.object is nil?
|
||||
ResourceIdentifier.for_type_with_id(type, id, serializable_resource_options)
|
||||
else
|
||||
# TODO(BF): Process relationship without evaluating lazy_association
|
||||
|
||||
@ -13,7 +13,7 @@ module ActiveModelSerializers
|
||||
type = inflect_type(type)
|
||||
type = type_for(:no_class_needed, type, options)
|
||||
if id.blank?
|
||||
{ type: type }
|
||||
nil
|
||||
else
|
||||
{ id: id.to_s, type: type }
|
||||
end
|
||||
|
||||
@ -36,6 +36,7 @@ module ActiveModelSerializers
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
expected = { data: nil }
|
||||
@ -46,7 +47,10 @@ module ActiveModelSerializers
|
||||
actual = build_serializer_and_serialize_relationship(model, relationship_name) do
|
||||
belongs_to :blog
|
||||
end
|
||||
|
||||
assert_equal(expected, actual)
|
||||
ensure
|
||||
ActiveModelSerializers.config.jsonapi_use_foreign_key_on_belongs_to_relationship = original_config
|
||||
end
|
||||
|
||||
def test_relationship_with_data_array
|
||||
|
||||
@ -147,8 +147,7 @@ module ActiveModelSerializers
|
||||
def test_for_type_with_id_given_blank_id
|
||||
id = ''
|
||||
actual = ResourceIdentifier.for_type_with_id('admin_user', id, {})
|
||||
expected = { type: 'admin-users' }
|
||||
assert_equal actual, expected
|
||||
assert_nil actual
|
||||
end
|
||||
|
||||
def test_for_type_with_id_inflected
|
||||
|
||||
Loading…
Reference in New Issue
Block a user