aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2016-06-25 18:09:36 +0800
committerGitHub <noreply@github.com>2016-06-25 18:09:36 +0800
commit6da5f6b451e27d59c2492e504350d0fc70c37e3a (patch)
treeb504543ea1269685e8373269d6c9e3054da20fac /activesupport
parentcbceb78f38a1e51d02c19cd33f7299f3d0a79e95 (diff)
parent236e6166880b8313a7447cc0bc91dc6501a834db (diff)
downloadrails-6da5f6b451e27d59c2492e504350d0fc70c37e3a.tar.gz
rails-6da5f6b451e27d59c2492e504350d0fc70c37e3a.tar.bz2
rails-6da5f6b451e27d59c2492e504350d0fc70c37e3a.zip
Merge pull request #25350 from tricknotes/uri-generic-as-json
Define `URI::Generic#as_json`
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/object/json.rb7
-rw-r--r--activesupport/test/json/encoding_test_cases.rb2
2 files changed, 9 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/json.rb b/activesupport/lib/active_support/core_ext/object/json.rb
index d49b2fbe54..32a41eafe4 100644
--- a/activesupport/lib/active_support/core_ext/object/json.rb
+++ b/activesupport/lib/active_support/core_ext/object/json.rb
@@ -1,6 +1,7 @@
# Hack to load json gem first so we can overwrite its to_json.
require 'json'
require 'bigdecimal'
+require 'uri/generic'
require 'active_support/core_ext/big_decimal/conversions' # for #to_s
require 'active_support/core_ext/hash/except'
require 'active_support/core_ext/hash/slice'
@@ -192,6 +193,12 @@ class DateTime
end
end
+class URI::Generic #:nodoc:
+ def as_json(options = nil)
+ to_s
+ end
+end
+
class Process::Status #:nodoc:
def as_json(options = nil)
{ :exitstatus => exitstatus, :pid => pid }
diff --git a/activesupport/test/json/encoding_test_cases.rb b/activesupport/test/json/encoding_test_cases.rb
index 0159ba8606..60d8685d32 100644
--- a/activesupport/test/json/encoding_test_cases.rb
+++ b/activesupport/test/json/encoding_test_cases.rb
@@ -76,6 +76,8 @@ module JSONTest
RegexpTests = [[ /^a/, '"(?-mix:^a)"' ], [/^\w{1,2}[a-z]+/ix, '"(?ix-m:^\\\\w{1,2}[a-z]+)"']]
+ URITests = [[ URI.parse('http://example.com'), %("http://example.com") ]]
+
DateTests = [[ Date.new(2005,2,1), %("2005/02/01") ]]
TimeTests = [[ Time.utc(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]]
DateTimeTests = [[ DateTime.civil(2005,2,1,15,15,10), %("2005/02/01 15:15:10 +0000") ]]