From ca12db0efbf07c1a3182556e99af4ebbfcd59dee Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Fri, 15 Nov 2013 10:29:38 -0800 Subject: [PATCH] Expanded coverage on JSON encoding --- activesupport/test/json/encoding_test.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index c28a8a6c24..1e32830ced 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -22,7 +22,7 @@ class TestJSONEncoding < ActiveSupport::TestCase @serialized = serialized end - def as_json(options) + def as_json(options = nil) @serialized end end @@ -338,7 +338,7 @@ class TestJSONEncoding < ActiveSupport::TestCase assert_equal(%([{"address":{"city":"London"}},{"address":{"city":"Paris"}}]), json) end - def test_to_json_should_not_keep_options_around + def test_hash_to_json_should_not_keep_options_around f = CustomWithOptions.new f.foo = "hello" f.bar = "world" @@ -348,6 +348,16 @@ class TestJSONEncoding < ActiveSupport::TestCase "other_hash" => {"foo"=>"other_foo","test"=>"other_test"}}, ActiveSupport::JSON.decode(hash.to_json)) end + def test_array_to_json_should_not_keep_options_around + f = CustomWithOptions.new + f.foo = "hello" + f.bar = "world" + + array = [f, {"foo" => "other_foo", "test" => "other_test"}] + assert_equal([{"foo"=>"hello","bar"=>"world"}, + {"foo"=>"other_foo","test"=>"other_test"}], ActiveSupport::JSON.decode(array.to_json)) + end + def test_hash_as_json_without_options json = { foo: OptionsTest.new }.as_json assert_equal({"foo" => :default}, json)