Fix relationship behavior when using block

When using the relationships DSL with a block e.g.
has_one :bio do
  link :self, "some_link"
end
the "data" field would be rendered with a nil value even though the bio
is not nil. This happened because the block return value was set to nil
but used as a value for the "data" field.
This commit is contained in:
Yohan Robert
2016-02-10 21:00:53 +01:00
parent 2c4193851b
commit b1fd43303c
3 changed files with 182 additions and 33 deletions

View File

@@ -17,18 +17,6 @@ module ActiveModel
link :yet_another do
"//example.com/resource/#{object.id}"
end
has_many :posts do
link :self do
href '//example.com/link_author/relationships/posts'
meta stuff: 'value'
end
link :related do
href '//example.com/link_author/posts'
meta count: object.posts.count
end
include_data false
end
end
def setup
@@ -91,23 +79,6 @@ module ActiveModel
}
assert_equal(expected, hash[:data][:links])
end
def test_relationship_links
hash = serializable(@author, adapter: :json_api).serializable_hash
expected = {
links: {
self: {
href: '//example.com/link_author/relationships/posts',
meta: { stuff: 'value' }
},
related: {
href: '//example.com/link_author/posts',
meta: { count: 1 }
}
}
}
assert_equal(expected, hash[:data][:relationships][:posts])
end
end
end
end