diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-01 17:34:50 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-01 17:34:50 +0000 |
commit | d99ac4f829dd0903f20e02de5dbba0ddc175c1f3 (patch) | |
tree | 18f7c54ef29c879c9a3c342bcea594bde36ca2b5 /test/json/test_json_rails.rb | |
parent | 596b68cc6b6333a3939ebca3ae09fecc491e5718 (diff) | |
download | ruby-d99ac4f829dd0903f20e02de5dbba0ddc175c1f3.tar.gz |
Add tests of JSON 1.1.9.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24729 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json/test_json_rails.rb')
-rw-r--r-- | test/json/test_json_rails.rb | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/test/json/test_json_rails.rb b/test/json/test_json_rails.rb index 91eb9ee9ea..341d3329ad 100644 --- a/test/json/test_json_rails.rb +++ b/test/json/test_json_rails.rb @@ -1,6 +1,12 @@ #!/usr/bin/env ruby +# -*- coding: utf-8 -*- require 'test/unit' +case ENV['JSON'] +when 'pure' then require 'json/pure' +when 'ext' then require 'json/ext' +else require 'json' +end require 'json/add/rails' require 'date' @@ -17,7 +23,7 @@ class TC_JSONRails < Test::Unit::TestCase def ==(other) a == other.a end - + def self.json_create(object) new(*object['args']) end @@ -50,13 +56,38 @@ class TC_JSONRails < Test::Unit::TestCase end end + class D + def initialize + @foo = 666 + end + + attr_reader :foo + + def ==(other) + foo == other.foo + end + end + def test_extended_json a = A.new(666) assert A.json_creatable? + assert_equal 666, a.a json = generate(a) a_again = JSON.parse(json) assert_kind_of a.class, a_again assert_equal a, a_again + assert_equal 666, a_again.a + end + + def test_extended_json_generic_object + d = D.new + assert D.json_creatable? + assert_equal 666, d.foo + json = generate(d) + d_again = JSON.parse(json) + assert_kind_of d.class, d_again + assert_equal d, d_again + assert_equal 666, d_again.foo end def test_extended_json_disabled @@ -85,11 +116,12 @@ class TC_JSONRails < Test::Unit::TestCase c = C.new # with rails addition all objects are theoretically creatable assert C.json_creatable? json = generate(c) - assert_raise(ArgumentError) { JSON.parse(json) } + assert_raises(ArgumentError) { JSON.parse(json) } end def test_raw_strings raw = '' + raw.respond_to?(:encode!) and raw.encode!(Encoding::ASCII_8BIT) raw_array = [] for i in 0..255 raw << i |