aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authornamusyaka <namusyaka@gmail.com>2016-02-16 11:35:52 +0900
committernamusyaka <namusyaka@gmail.com>2016-04-09 23:49:43 +0900
commit91386c1b355947955b05ee3846e4aedd4eec0eb1 (patch)
treec09bcb439aea67fd1cefd88f91da0ad1ad3e8593 /activesupport
parente88d63e6f7a7e9a73484ea30859bf3b75a4b7188 (diff)
downloadrails-91386c1b355947955b05ee3846e4aedd4eec0eb1.tar.gz
rails-91386c1b355947955b05ee3846e4aedd4eec0eb1.tar.bz2
rails-91386c1b355947955b05ee3846e4aedd4eec0eb1.zip
Fix behavior of JSON encoding for Exception
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/CHANGELOG.md4
-rw-r--r--activesupport/lib/active_support/core_ext/object/json.rb6
-rw-r--r--activesupport/test/json/encoding_test.rb5
3 files changed, 15 insertions, 0 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md
index bf1ffe8992..5729a98b99 100644
--- a/activesupport/CHANGELOG.md
+++ b/activesupport/CHANGELOG.md
@@ -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})/)
diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb
index 0db787010c..d49b2fbe54 100644
--- a/activesupport/lib/active_support/core_ext/object/json.rb
+++ b/activesupport/lib/active_support/core_ext/object/json.rb
@@ -197,3 +197,9 @@ class Process::Status #:nodoc:
{ :exitstatus => exitstatus, :pid => pid }
end
end
+
+class Exception
+ def as_json(options = nil)
+ to_s
+ end
+end
diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb
index 9f4b62fd8b..5fc2e16336 100644
--- a/activesupport/test/json/encoding_test.rb
+++ b/activesupport/test/json/encoding_test.rb
@@ -422,6 +422,11 @@ EXPECTED
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)