提交 87c2c070 编写于 作者: E Eileen M. Uchitelle

Merge pull request #23702 from namusyaka/fix-json-behavior

Fix behavior of JSON encoding for Exception
* Fix behavior of JSON encoding for `Exception`.
*namusyaka*
* Make `number_to_phone` format number with regexp pattern.
number_to_phone(18812345678, pattern: /(\d{3})(\d{4})(\d{4})/)
......
......@@ -197,3 +197,9 @@ def as_json(options = nil)
{ :exitstatus => exitstatus, :pid => pid }
end
end
class Exception
def as_json(options = nil)
to_s
end
end
......@@ -422,6 +422,11 @@ def test_twz_to_json_when_wrapping_a_date_time
assert_equal '"1999-12-31T19:00:00.000-05:00"', ActiveSupport::JSON.encode(time)
end
def test_exception_to_json
exception = Exception.new("foo")
assert_equal '"foo"', ActiveSupport::JSON.encode(exception)
end
protected
def object_keys(json_object)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册