aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/json
diff options
context:
space:
mode:
authorEileen Uchitelle <eileencodes@gmail.com>2018-10-11 15:28:52 -0400
committerEileen Uchitelle <eileencodes@gmail.com>2018-10-11 15:28:52 -0400
commit8df7ed3b88fc9f19446d7207a745a331893b81cd (patch)
tree0d501460cbe2aa81ae7a4059cff85ea0cc5a1625 /activesupport/test/json
parent92a796bf6d9eead4c56f666617754072694b1d0a (diff)
downloadrails-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.
Diffstat (limited to 'activesupport/test/json')
-rw-r--r--activesupport/test/json/encoding_test.rb10
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",