提交 ca12db0e 编写于 作者: G Godfrey Chan

Expanded coverage on JSON encoding

上级 cfaa2aa9
......@@ -22,7 +22,7 @@ def initialize(serialized)
@serialized = serialized
end
def as_json(options)
def as_json(options = nil)
@serialized
end
end
......@@ -338,7 +338,7 @@ def test_enumerable_should_pass_encoding_options_to_children_in_to_json
assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json)
end
def test_to_json_should_not_keep_options_around
def test_hash_to_json_should_not_keep_options_around
f = CustomWithOptions.new
f.foo = "hello"
f.bar = "world"
......@@ -348,6 +348,16 @@ def test_to_json_should_not_keep_options_around
"other_hash" => {"foo"=>"other_foo","test"=>"other_test"}}, ActiveSupport::JSON.decode(hash.to_json))
end
def test_array_to_json_should_not_keep_options_around
f = CustomWithOptions.new
f.foo = "hello"
f.bar = "world"
array = [f, {"foo" => "other_foo", "test" => "other_test"}]
assert_equal([{"foo"=>"hello","bar"=>"world"},
{"foo"=>"other_foo","test"=>"other_test"}], ActiveSupport::JSON.decode(array.to_json))
end
def test_hash_as_json_without_options
json = { foo: OptionsTest.new }.as_json
assert_equal({"foo" => :default}, json)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册