From 8df7ed3b88fc9f19446d7207a745a331893b81cd Mon Sep 17 00:00:00 2001 From: Eileen Uchitelle Date: Thu, 11 Oct 2018 15:28:52 -0400 Subject: [PATCH] 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. --- activesupport/test/json/encoding_test.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index ebc5df14dd..8062873386 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -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", -- GitLab