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

@@ -42,17 +42,17 @@ module ActiveModel
def link(name, value = nil, &block)
@_links[name] = block || value
nil
:nil
end
def meta(value = nil, &block)
@_meta = block || value
nil
:nil
end
def include_data(value = true)
@_include_data = value
nil
:nil
end
def value(serializer)
@@ -60,7 +60,12 @@ module ActiveModel
@scope = serializer.scope
if block
instance_eval(&block)
block_value = instance_eval(&block)
if block_value == :nil
serializer.read_attribute_for_serialization(name)
else
block_value
end
else
serializer.read_attribute_for_serialization(name)
end