Permalink
Browse files

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

Fix behavior of JSON encoding for Exception
  • Loading branch information...
eileencodes committed Apr 9, 2016
2 parents e88d63e + 91386c1 commit 87c2c070c4cf1b62ac364c53496a2da000fbf9d6
@@ -1,3 +1,7 @@
+* 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)

0 comments on commit 87c2c07

Please sign in to comment.