Skip to content

Commit

Permalink
Test that nested structs to_json works as expected
Browse files Browse the repository at this point in the history
Check that options passed to the to_json are passed to all objects that
respond to as_json.
  • Loading branch information
eileencodes committed Oct 11, 2018
1 parent 92a796b commit 8df7ed3
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions activesupport/test/json/encoding_test.rb
Expand Up @@ -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",
Expand Down

0 comments on commit 8df7ed3

Please sign in to comment.