提交 3f63ac4e 编写于 作者: S Sean Griffin

Correctly determine if an attribute is uninitialized

In real usage, we give the builder a types hash with a default value of
`Type::Value.new`. This means we need to explicitly check for the key,
rather than the truthiness of the type to determine if it's a known but
uninitialized attribute
上级 0f29c216
......@@ -65,7 +65,7 @@ def assign_default_proc
if values.key?(name)
hash[name] = Attribute.from_database(name, values[name], type)
elsif type
elsif types.key?(name)
hash[name] = Attribute.uninitialized(name, type)
end
end
......
......@@ -109,7 +109,15 @@ class AttributeSetTest < ActiveRecord::TestCase
test "fetch_value returns nil for unknown attributes" do
attributes = attributes_with_uninitialized_key
assert_nil attributes.fetch_value(:wibble)
assert_nil attributes.fetch_value(:wibble) { "hello" }
end
test "fetch_value returns nil for unknown attributes when types has a default" do
types = Hash.new(Type::Value.new)
builder = AttributeSet::Builder.new(types)
attributes = builder.build_from_database
assert_nil attributes.fetch_value(:wibble) { "hello" }
end
test "fetch_value uses the given block for uninitialized attributes" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册