提交 abbf00e5 编写于 作者: R Ryunosuke Sato

Define `Pathname#as_json`

When the Pathname object is converted as JSON,
it should be a string that means itself.

Expected:
```
>> Pathname.new('/path/to/somewhere.txt').as_json
"/path/to/somewhere.txt"
```

Actual:
```
>> Pathname.new('/path/to/somewhere.txt').as_json
{"path"=>"/path/to/somewhere.txt"}
```
上级 6da5f6b4
......@@ -2,6 +2,7 @@
require 'json'
require 'bigdecimal'
require 'uri/generic'
require 'pathname'
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'
......@@ -199,6 +200,12 @@ def as_json(options = nil)
end
end
class Pathname #:nodoc:
def as_json(options = nil)
to_s
end
end
class Process::Status #:nodoc:
def as_json(options = nil)
{ :exitstatus => exitstatus, :pid => pid }
......
......@@ -78,6 +78,8 @@ module EncodingTestCases
URITests = [[ URI.parse('http://example.com'), %("http://example.com") ]]
PathnameTests = [[ Pathname.new('lib/index.rb'), %("lib/index.rb") ]]
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") ]]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册