diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2016-06-25 18:09:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-25 18:09:36 +0800 |
commit | 6da5f6b451e27d59c2492e504350d0fc70c37e3a (patch) | |
tree | b504543ea1269685e8373269d6c9e3054da20fac | |
parent | cbceb78f38a1e51d02c19cd33f7299f3d0a79e95 (diff) | |
parent | 236e6166880b8313a7447cc0bc91dc6501a834db (diff) | |
download | rails-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`
-rw-r--r-- | activesupport/lib/active_support/core_ext/object/json.rb | 7 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test_cases.rb | 2 |
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") ]] |