1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #4250 from lest/range-json

use #to_s to convert Range to json
This commit is contained in:
Xavier Noria 2012-01-02 13:53:52 -08:00
commit e04232e904
2 changed files with 8 additions and 0 deletions

View file

@ -206,6 +206,10 @@ module Enumerable
end
end
class Range
def as_json(options = nil) to_s end #:nodoc:
end
class Array
def as_json(options = nil) #:nodoc:
# use encoder as a proxy to call as_json on all elements, to protect from circular references

View file

@ -38,6 +38,10 @@ class TestJSONEncoding < Test::Unit::TestCase
ArrayTests = [[ ['a', 'b', 'c'], %([\"a\",\"b\",\"c\"]) ],
[ [1, 'a', :b, nil, false], %([1,\"a\",\"b\",null,false]) ]]
RangeTests = [[ 1..2, %("1..2")],
[ 1...2, %("1...2")],
[ 1.5..2.5, %("1.5..2.5")]]
SymbolTests = [[ :a, %("a") ],
[ :this, %("this") ],
[ :"a b", %("a b") ]]