summaryrefslogtreecommitdiff
path: root/test/json/test_json_generic_object.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-12 03:05:45 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-12 03:05:45 +0000
commit062d2ee6f798205c3046730d0d348cfd0d0bc09d (patch)
tree8be6c2e72c796c481906978565bc116661e4fe9a /test/json/test_json_generic_object.rb
parentf1194eb9b08b7c7be39e168c1f9620e377bee472 (diff)
* ext/json: merge JSON 1.7.7.
This includes security fix. [CVE-2013-0269] https://github.com/flori/json/commit/d0a62f3ced7560daba2ad546d83f0479a5ae2cf2 https://groups.google.com/d/topic/rubyonrails-security/4_YvCpLzL58/discussion git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/json/test_json_generic_object.rb')
-rw-r--r--test/json/test_json_generic_object.rb43
1 files changed, 34 insertions, 9 deletions
diff --git a/test/json/test_json_generic_object.rb b/test/json/test_json_generic_object.rb
index e13a492..77ef22e 100644
--- a/test/json/test_json_generic_object.rb
+++ b/test/json/test_json_generic_object.rb
@@ -1,5 +1,5 @@
#!/usr/bin/env ruby
-# -*- coding: utf-8 -*-
+# encoding: utf-8
require 'test/unit'
require File.join(File.dirname(__FILE__), 'setup_variant')
@@ -20,16 +20,41 @@ class TestJSONGenericObject < Test::Unit::TestCase
end
def test_generate_json
- assert_equal @go, JSON(JSON(@go))
+ switch_json_creatable do
+ assert_equal @go, JSON(JSON(@go), :create_additions => true)
+ end
end
def test_parse_json
- assert_equal @go, l = JSON('{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }')
- assert_equal 1, l.a
- assert_equal @go, l = JSON('{ "a": 1, "b": 2 }', :object_class => GenericObject)
- assert_equal 1, l.a
- assert_equal GenericObject[:a => GenericObject[:b => 2]],
- l = JSON('{ "a": { "b": 2 } }', :object_class => GenericObject)
- assert_equal 2, l.a.b
+ assert_kind_of Hash, JSON('{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }', :create_additions => true)
+ switch_json_creatable do
+ assert_equal @go, l = JSON('{ "json_class": "JSON::GenericObject", "a": 1, "b": 2 }', :create_additions => true)
+ assert_equal 1, l.a
+ assert_equal @go, l = JSON('{ "a": 1, "b": 2 }', :object_class => GenericObject)
+ assert_equal 1, l.a
+ assert_equal GenericObject[:a => GenericObject[:b => 2]],
+ l = JSON('{ "a": { "b": 2 } }', :object_class => GenericObject)
+ assert_equal 2, l.a.b
+ end
+ end
+
+ def test_from_hash
+ result = GenericObject.from_hash(
+ :foo => { :bar => { :baz => true }, :quux => [ { :foobar => true } ] })
+ assert_kind_of GenericObject, result.foo
+ assert_kind_of GenericObject, result.foo.bar
+ assert_equal true, result.foo.bar.baz
+ assert_kind_of GenericObject, result.foo.quux.first
+ assert_equal true, result.foo.quux.first.foobar
+ assert_equal true, GenericObject.from_hash(true)
+ end
+
+ private
+
+ def switch_json_creatable
+ JSON::GenericObject.json_creatable = true
+ yield
+ ensure
+ JSON::GenericObject.json_creatable = false
end
end