diff options
author | Eileen M. Uchitelle <eileencodes@gmail.com> | 2016-04-09 12:57:08 -0400 |
---|---|---|
committer | Eileen M. Uchitelle <eileencodes@gmail.com> | 2016-04-09 12:57:08 -0400 |
commit | 87c2c070c4cf1b62ac364c53496a2da000fbf9d6 (patch) | |
tree | c09bcb439aea67fd1cefd88f91da0ad1ad3e8593 | |
parent | e88d63e6f7a7e9a73484ea30859bf3b75a4b7188 (diff) | |
parent | 91386c1b355947955b05ee3846e4aedd4eec0eb1 (diff) | |
download | rails-87c2c070c4cf1b62ac364c53496a2da000fbf9d6.tar.gz rails-87c2c070c4cf1b62ac364c53496a2da000fbf9d6.tar.bz2 rails-87c2c070c4cf1b62ac364c53496a2da000fbf9d6.zip |
Merge pull request #23702 from namusyaka/fix-json-behavior
Fix behavior of JSON encoding for Exception
-rw-r--r-- | activesupport/CHANGELOG.md | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/json.rb | 6 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 5 |
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) |