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.
This commit is contained in:
Eileen Uchitelle 2018-10-11 15:28:52 -04:00
parent 92a796bf6d
commit 8df7ed3b88
1 changed files with 10 additions and 0 deletions

View File

@ -157,6 +157,16 @@ class TestJSONEncoding < ActiveSupport::TestCase
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",