diff options
author | Eileen Uchitelle <eileencodes@gmail.com> | 2018-10-11 15:28:52 -0400 |
---|---|---|
committer | Eileen Uchitelle <eileencodes@gmail.com> | 2018-10-11 15:28:52 -0400 |
commit | 8df7ed3b88fc9f19446d7207a745a331893b81cd (patch) | |
tree | 0d501460cbe2aa81ae7a4059cff85ea0cc5a1625 | |
parent | 92a796bf6d9eead4c56f666617754072694b1d0a (diff) | |
download | rails-8df7ed3b88fc9f19446d7207a745a331893b81cd.tar.gz rails-8df7ed3b88fc9f19446d7207a745a331893b81cd.tar.bz2 rails-8df7ed3b88fc9f19446d7207a745a331893b81cd.zip |
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.
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 10 |
1 files changed, 10 insertions, 0 deletions
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 @@ 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", |