diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2012-01-01 20:16:10 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2012-01-01 20:16:10 +0300 |
commit | dc05914be766583a22c959b2df64cfd2dfe88732 (patch) | |
tree | ed42f6e7242db34ef44c380ec50f15b317ee7247 | |
parent | f3e079e8b54da1c4d0511495ced3f68c1b7a46f1 (diff) | |
download | rails-dc05914be766583a22c959b2df64cfd2dfe88732.tar.gz rails-dc05914be766583a22c959b2df64cfd2dfe88732.tar.bz2 rails-dc05914be766583a22c959b2df64cfd2dfe88732.zip |
use #to_s to convert Range to json
-rw-r--r-- | activesupport/lib/active_support/json/encoding.rb | 4 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb index d7181035d3..07b6a940c6 100644 --- a/activesupport/lib/active_support/json/encoding.rb +++ b/activesupport/lib/active_support/json/encoding.rb @@ -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 diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index a6435a763a..bebad18e99 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -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") ]] |