提交 f2f6a39c 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #26640 from Shopify/fix-am-errors-to-hash-default-proc

Do not leak the Errors default proc when calling to_hash or as_json
......@@ -280,7 +280,7 @@ def to_hash(full_messages = false)
messages[attribute] = array.map { |message| full_message(attribute, message) }
end
else
messages.dup
without_default_proc(messages)
end
end
......
......@@ -250,6 +250,16 @@ def test_no_key
assert_equal({ name: ["cannot be blank"] }, person.errors.to_hash)
end
test "to_hash returns a hash without default proc" do
person = Person.new
assert_nil person.errors.to_hash.default_proc
end
test "as_json returns a hash without default proc" do
person = Person.new
assert_nil person.errors.as_json.default_proc
end
test "full_messages creates a list of error messages with the attribute name included" do
person = Person.new
person.errors.add(:name, "cannot be blank")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册