提交 8df7ed3b 编写于 作者: E Eileen Uchitelle

Test that nested structs to_json works as expected

Check that options passed to the to_json are passed to all objects that
respond to as_json.
上级 92a796bf
......@@ -157,6 +157,16 @@ def test_struct_to_json_with_options
assert_equal({ "foo" => "hello" }, JSON.parse(json))
end
def test_struct_to_json_with_options_nested
klass = Struct.new(:foo, :bar)
struct = klass.new "hello", "world"
parent_struct = klass.new struct, "world"
json = parent_struct.to_json only: [:foo]
assert_equal({ "foo" => { "foo" => "hello" } }, JSON.parse(json))
end
def test_hash_should_pass_encoding_options_to_children_in_as_json
person = {
name: "John",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册