mirror of
https://github.com/ditkrg/active_model_serializers.git
synced 2026-01-25 15:23:06 +00:00
Remove nil relationships links (#1833)
This commit is contained in:
@@ -13,8 +13,9 @@ module ActiveModel
|
||||
end
|
||||
|
||||
has_one :profile do
|
||||
id = object.profile.id
|
||||
link :related do
|
||||
"//example.com/profiles/#{object.profile.id}"
|
||||
"//example.com/profiles/#{id}" if id != 123
|
||||
end
|
||||
end
|
||||
|
||||
@@ -113,6 +114,14 @@ module ActiveModel
|
||||
assert_relationship(:profile, expected)
|
||||
end
|
||||
|
||||
def test_relationship_nil_link
|
||||
@author.profile.id = 123
|
||||
expected = {
|
||||
data: { id: '123', type: 'profiles' }
|
||||
}
|
||||
assert_relationship(:profile, expected)
|
||||
end
|
||||
|
||||
def test_relationship_block_link_href
|
||||
expected = {
|
||||
data: [{ id: '1337', type: 'locations' }],
|
||||
|
||||
Reference in New Issue
Block a user